summaryrefslogtreecommitdiffstats
path: root/wp-includes/sitemaps
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 07:57:26 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 07:57:26 +0000
commit30883c26bdceb9eaf32c8d4a1b0c1bce223b5226 (patch)
tree39a02e2aeb21ab5b7923c6f5757d66d55b708912 /wp-includes/sitemaps
parentAdding upstream version 6.4.3+dfsg1. (diff)
downloadwordpress-30883c26bdceb9eaf32c8d4a1b0c1bce223b5226.tar.xz
wordpress-30883c26bdceb9eaf32c8d4a1b0c1bce223b5226.zip
Adding upstream version 6.5+dfsg1.upstream/6.5+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'wp-includes/sitemaps')
-rw-r--r--wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php26
1 files changed, 25 insertions, 1 deletions
diff --git a/wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php b/wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php
index dff85a7..7436f5f 100644
--- a/wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php
+++ b/wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php
@@ -112,6 +112,29 @@ class WP_Sitemaps_Posts extends WP_Sitemaps_Provider {
'loc' => home_url( '/' ),
);
+ /*
+ * Get the most recent posts displayed on the homepage,
+ * and then sort them by their modified date to find
+ * the date the homepage was approximately last updated.
+ */
+ $latest_posts = new WP_Query(
+ array(
+ 'post_type' => 'post',
+ 'post_status' => 'publish',
+ 'orderby' => 'date',
+ 'order' => 'DESC',
+ 'no_found_rows' => true,
+ 'update_post_meta_cache' => false,
+ 'update_post_term_cache' => false,
+ )
+ );
+
+ if ( ! empty( $latest_posts->posts ) ) {
+ $posts = wp_list_sort( $latest_posts->posts, 'post_modified_gmt', 'DESC' );
+
+ $sitemap_entry['lastmod'] = wp_date( DATE_W3C, strtotime( $posts[0]->post_modified_gmt ) );
+ }
+
/**
* Filters the sitemap entry for the home page when the 'show_on_front' option equals 'posts'.
*
@@ -125,7 +148,8 @@ class WP_Sitemaps_Posts extends WP_Sitemaps_Provider {
foreach ( $query->posts as $post ) {
$sitemap_entry = array(
- 'loc' => get_permalink( $post ),
+ 'loc' => get_permalink( $post ),
+ 'lastmod' => wp_date( DATE_W3C, strtotime( $post->post_modified_gmt ) ),
);
/**