equal
deleted
inserted
replaced
110 // Extract the data needed for home URL to add to the array. |
110 // Extract the data needed for home URL to add to the array. |
111 $sitemap_entry = array( |
111 $sitemap_entry = array( |
112 'loc' => home_url( '/' ), |
112 'loc' => home_url( '/' ), |
113 ); |
113 ); |
114 |
114 |
|
115 /* |
|
116 * Get the most recent posts displayed on the homepage, |
|
117 * and then sort them by their modified date to find |
|
118 * the date the homepage was approximately last updated. |
|
119 */ |
|
120 $latest_posts = new WP_Query( |
|
121 array( |
|
122 'post_type' => 'post', |
|
123 'post_status' => 'publish', |
|
124 'orderby' => 'date', |
|
125 'order' => 'DESC', |
|
126 'no_found_rows' => true, |
|
127 'update_post_meta_cache' => false, |
|
128 'update_post_term_cache' => false, |
|
129 ) |
|
130 ); |
|
131 |
|
132 if ( ! empty( $latest_posts->posts ) ) { |
|
133 $posts = wp_list_sort( $latest_posts->posts, 'post_modified_gmt', 'DESC' ); |
|
134 |
|
135 $sitemap_entry['lastmod'] = wp_date( DATE_W3C, strtotime( $posts[0]->post_modified_gmt ) ); |
|
136 } |
|
137 |
115 /** |
138 /** |
116 * Filters the sitemap entry for the home page when the 'show_on_front' option equals 'posts'. |
139 * Filters the sitemap entry for the home page when the 'show_on_front' option equals 'posts'. |
117 * |
140 * |
118 * @since 5.5.0 |
141 * @since 5.5.0 |
119 * |
142 * |
123 $url_list[] = $sitemap_entry; |
146 $url_list[] = $sitemap_entry; |
124 } |
147 } |
125 |
148 |
126 foreach ( $query->posts as $post ) { |
149 foreach ( $query->posts as $post ) { |
127 $sitemap_entry = array( |
150 $sitemap_entry = array( |
128 'loc' => get_permalink( $post ), |
151 'loc' => get_permalink( $post ), |
|
152 'lastmod' => wp_date( DATE_W3C, strtotime( $post->post_modified_gmt ) ), |
129 ); |
153 ); |
130 |
154 |
131 /** |
155 /** |
132 * Filters the sitemap entry for an individual post. |
156 * Filters the sitemap entry for an individual post. |
133 * |
157 * |
191 |
215 |
192 /** |
216 /** |
193 * Returns the query args for retrieving posts to list in the sitemap. |
217 * Returns the query args for retrieving posts to list in the sitemap. |
194 * |
218 * |
195 * @since 5.5.0 |
219 * @since 5.5.0 |
|
220 * @since 6.1.0 Added `ignore_sticky_posts` default parameter. |
196 * |
221 * |
197 * @param string $post_type Post type name. |
222 * @param string $post_type Post type name. |
198 * @return array Array of WP_Query arguments. |
223 * @return array Array of WP_Query arguments. |
199 */ |
224 */ |
200 protected function get_posts_query_args( $post_type ) { |
225 protected function get_posts_query_args( $post_type ) { |
202 * Filters the query arguments for post type sitemap queries. |
227 * Filters the query arguments for post type sitemap queries. |
203 * |
228 * |
204 * @see WP_Query for a full list of arguments. |
229 * @see WP_Query for a full list of arguments. |
205 * |
230 * |
206 * @since 5.5.0 |
231 * @since 5.5.0 |
|
232 * @since 6.1.0 Added `ignore_sticky_posts` default parameter. |
207 * |
233 * |
208 * @param array $args Array of WP_Query arguments. |
234 * @param array $args Array of WP_Query arguments. |
209 * @param string $post_type Post type name. |
235 * @param string $post_type Post type name. |
210 */ |
236 */ |
211 $args = apply_filters( |
237 $args = apply_filters( |
217 'posts_per_page' => wp_sitemaps_get_max_urls( $this->object_type ), |
243 'posts_per_page' => wp_sitemaps_get_max_urls( $this->object_type ), |
218 'post_status' => array( 'publish' ), |
244 'post_status' => array( 'publish' ), |
219 'no_found_rows' => true, |
245 'no_found_rows' => true, |
220 'update_post_term_cache' => false, |
246 'update_post_term_cache' => false, |
221 'update_post_meta_cache' => false, |
247 'update_post_meta_cache' => false, |
|
248 'ignore_sticky_posts' => true, // Sticky posts will still appear, but they won't be moved to the front. |
222 ), |
249 ), |
223 $post_type |
250 $post_type |
224 ); |
251 ); |
225 |
252 |
226 return $args; |
253 return $args; |