Make WordPress Core

Opened 13 years ago

Closed 10 years ago

Last modified 10 years ago

#15905 closed defect (bug) (duplicate)

Using wp_list_comments using both the type and callback arguments causes the first comment to be repeated

Reported by: benschell's profile benschell Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Comments Keywords: close
Focuses: Cc:

Description

I'm using wp_list_comments like so:

	<ol class="commentlist">
	<?php wp_list_comments('callback=comment_callback&type=comment'); ?>
	</ol>

When including the comments on a page listing many posts (like the home index page), the callback function is always passed the first comment that is encountered. Trying get_comments before wp_list_comments shows the proper comments that should be displayed, but the callback always receives the same comment as it's argument.

Removing '&type=comment' yields the expected output. My current workaround is to remove '&type=comment' and only respond to comments with an empty string for the comment_type in my comment callback function.

Change History (5)

#1 @nacin
13 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release

#2 @benschell
13 years ago

  • Cc ben@… added

I've narrowed this bug down but, since this is my first foray into the core of Wordpress, I'm not exactly sure where the fix should be applied.

In this specific use case, I'm calling wp_list_comments on an index page; that is, I'm doing a loop, calling the_post() in each loop, then calling wp_list_comments() while displaying each post to present its comments. Between source:trunk/wp-includes/comment-template.php#L1426 and L1450, the set of comments that should be displayed is determined. When the 'type' argument is set, $wp_query->comments_by_type is checked and used if present. If not, $wp_query->comments is separated into type (by separate_comments()), stored at $wp_query->comments_by_type, and that outcome used for display.

The bug is in this use of $wp_query->comments_by_type; when the_post() is called, $wp_query->comments is reset but $wp_query->comments_by_type is not. So, when the next post is displayed and wp_list_comments() is called, $wp_query->comments_by_type is not empty, but is invalid as it contains the comments from the previous post.

I'm not sure that $wp_query->comments_by_type should be reset in query.php (when $wp_query->comments is set) since the only use (in core) of comments_by_type is in comment-template.php. Other than storing additional information (what post comments_by_type came from) or not caching the result of separate_comments on $wp_query, I can't figure out a good way to patch comment-template.php . But, maybe this analysis will help the proper maintainer come up with a patch? I'm happy to come up with a patch and/or provide testing assistance if the appropriate maintainer has a preference/suggestion on how this should be fixed.

#3 @solarissmoke
13 years ago

  • Keywords close added; needs-patch removed

Think this is a duplicate of #14809

#4 @chriscct7
10 years ago

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

Duplicate of #14809.

#5 @DrewAPicture
10 years ago

  • Milestone Future Release deleted
Note: See TracTickets for help on using tickets.