From caf041d76e7f06274391a8c6d5f42d964bb2e71f Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Sun, 14 Jun 2015 18:36:14 +0000 Subject: [PATCH] Improve lastBuildDate timestamp in rss feeds RSS feed timestamps should reflect the actual timestamps for those RSS feeds rather than the generic timestamp for all posts and all comments. Props stevenkword. Fixes #4575. git-svn-id: https://develop.svn.wordpress.org/trunk@32765 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/feed-rss2-comments.php | 2 +- src/wp-includes/feed-rss2.php | 2 +- src/wp-includes/feed.php | 34 ++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/feed-rss2-comments.php b/src/wp-includes/feed-rss2-comments.php index c8e8d498ea..73d92ce6cc 100644 --- a/src/wp-includes/feed-rss2-comments.php +++ b/src/wp-includes/feed-rss2-comments.php @@ -43,7 +43,7 @@ do_action( 'rss_tag_pre', 'rss2-comments' ); - + " rel="self" type="application/rss+xml" /> - + have_posts() ) { + $post_ids = array(); + foreach( $wp_query->posts as $post ) { + $post_ids[] = $post->ID; + $post_times[] = $post->post_modified_gmt; + } + $postids = implode( "','", $post_ids ); + $max_post_time = max( $post_times ); + + if( $wp_query->is_comment_feed() ) { + $max_comment_time = $wpdb->get_var( $wpdb->prepare( "SELECT MAX(comment_date_gmt) FROM $wpdb->comments WHERE comment_post_ID IN ('%s') AND comment_approved = '1'", $postids ) ); + + return max( $max_post_time, $max_comment_time ); + } + return $max_post_time; + } + + // Fallback to last time any post was modified or published. + return get_lastpostmodified( 'GMT' ); +} + /** * Retrieve the blog title for the feed title. *