Make WordPress Core

Opened 16 years ago

Closed 14 years ago

#137 closed defect (bug) (fixed)

Comments feed modification time is based on posts, not comments

Reported by: kelson Owned by: ryan
Milestone: 2.1 Priority: normal
Severity: minor Version: 2.0
Component: General Keywords: has-patch, needs-testing
Focuses: Cc:


When determining the last-modified date for the comments feed, WP only checks the latest modification of the posts, not comments. As a result, if there's a new comment but not a new post, it uses the older time and will give aggregators a "Not Modified" response.

Attachments (4)

0000137-comments_feed_modtime.patch (2.5 KB) - added by kelson 15 years ago.
comments-feed-last-modified.patch (645 bytes) - added by chrisdolan 15 years ago.
Update to support feed=comments-rss2
last-modified-comments.patch (441 bytes) - added by colinleroy 15 years ago.
Same patch, not broken as in the my comment
137.diff (2.6 KB) - added by mdawaffe 14 years ago.

Download all attachments as: .zip

Change History (19)

#2 @hugo
16 years ago

Here is the getlastcommentmodified function. It is based on the lastpostmodified function. It only looks at post_date_gmt and post_date.

function get_lastcommentmodified($timezone = 'server') {

global $tablecomments, $cache_lastcommentmodified, $pagenow, $wpdb;
$add_seconds_blog = get_settings('gmt_offset') * 3600;
$add_seconds_server = date('Z');
$now = current_time('mysql', 1);
if ( !isset($cache_lastcommentmodified[$timezone]) ) {

switch(strtolower($timezone)) {

case 'gmt':

$lastcommentmodified = $wpdb->get_var("SELECT co

mment_date_gmt FROM $tablecomments WHERE comment_date_gmt <= '$now' ORDER BY com
ment_date_gmt DESC LIMIT 1");


case 'blog':

$lastcommentmodified = $wpdb->get_var("SELECT co

mment_date FROM $tablecomments WHERE comment_date_gmt <= '$now' ORDER BY comment
_date_gmt DESC LIMIT 1");


case 'server':

$lastcommentmodified = $wpdb->get_var("SELECT DA

TE_ADD(comment_date_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $tablecomme
nts WHERE comment_date_gmt <= '$now' ORDER BY comment_date_gmt DESC LIMIT 1");


$cache_lastcommentmodified[$timezone] = $lastcommentmodified;

} else {

$lastcommentmodified = $cache_lastcommentmodified[$timezone];

return $lastcommentmodified;


#3 @hugo
16 years ago

You have to additionally use get_lastcommentmodified in wp_blog_header.php as follows:

if ($withcomments) {

$wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastcomment

modified('GMT'), 0).' GMT';

} else {

$wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastpostmod

ified('GMT'), 0).' GMT';


And you need to do the "move exit out of ifs" from the bug 133 to make 304 status usefull. And you need to set $withcomments = 1 in wp-commentsrss2.php directly before the require for wp-blog-header.

#4 @kelson
16 years ago

The function hugo posted seems to work. I added it and changed the call in wp-blog-header.php on the 2nd, and it's been working fine since then. It even handles the case where I go in and edit a recent comment.

#5 @anonymousbugger
16 years ago

Is anyone doing anything with this? It's been two months since the last post, and that was me reporting that the fix suggested here had been working fine on my site for the previous several weeks.

Without this fix, no one will see updates to the comments feed until you post a new article.

#6 @kelson
16 years ago

There's been a working fix for this for 3 months and no activity. (And apparently no owner?) On the theory that what's holding it up is the lack of a patch... here's a patch.

I should mention that the severity is higher now than it originally was, because it used to be masked by bug 133. Now that that's fixed, this becomes an issue. If you only post once a week, but several people comment each day, your comments feed will not update for the entire week.

#7 @matt
16 years ago

  • Owner changed from anonymous to matt
  • Resolution changed from 10 to 20
  • Status changed from new to closed

15 years ago

Update to support feed=comments-rss2

#9 @chrisdolan
15 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Version changed from 1.2 to 1.5.2

(note: this is against the 1.5.2 branch. I'm not working on the SVN trunk. Apologies if this is consequently out of date)

This is broken in v1.5.2 when used with the index.php?feed=comments-rss2 URL (not with the index.php/comments/feed/ URL). I just attached a very crude patch that fixes the problem. A more sophisticated patch would either deprecate the feed=comments-rss2 URL or build that into the $withcomments flag.

#10 @colinleroy
15 years ago

I have this problem with wp 2.0. Using the permalink to a post's commentRSS feed, in the following form: http://$website/$wp-base/archives/2005/12/21/$post-name/feed/ , the variable withcomments isn't set and hence, the Last-Modified header doesn't use the latest comment's date.

Here's the patch I use to fix it:
Index: wp-includes/classes.php
--- wp-includes/classes.php (revision 3428)
+++ wp-includes/classes.php (working copy)
@@ -1575,6 +1575,10 @@

$this->did_permalink = false;


+ if ($query_varsname? && $query_varsfeed?)
+ $query_varswithcomments?=1;


$this->public_query_vars = apply_filters('query_vars', $this->public_query_vars);


15 years ago

Same patch, not broken as in the my comment

#11 @leftjustified
14 years ago

  • Cc hugo removed
  • Keywords bg|has-patch bg|needs-testing added
  • Version changed from 1.5.2 to 2.0

Trying to clean up the 'needs-patch' category :)

#12 @ryan
14 years ago

  • Owner changed from matt to ryan
  • Status changed from reopened to new

#13 @foolswisdom
14 years ago

  • Keywords has-patch needs-testing added; bg|has-patch bg|needs-testing removed
  • Milestone set to 2.1

14 years ago

#14 @mdawaffe
14 years ago


  1. adds 'withoutcomments' query var
  2. send_headers() checks last modified comment if withcomments or if !withoutcomments and one of the is_sigular query vars is set.

#15 @ryan
14 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [4483]) Base last modified time for comment feeds on comments, not the post. Props mdawaffe. fixes #137

Note: See TracTickets for help on using tickets.