Ticket #14809 (new defect (bug))

Opened 21 months ago

Last modified 11 months ago

comments_by_type doesn't always get reset

Reported by: nmassey Owned by:
Priority: normal Milestone: Future Release
Component: Comments Version: 3.0.1
Severity: minor Keywords: reporter-feedback
Cc:

Description

in wp-includes/comment-template.php , in function comments_template(), it is possible for $wp_query->comments to be set but for $wp_query->comments_by_type NOT to get reset when it should be reset to array(). We ran into a bug because:

  • on a single page (actually inside of a widget), we were pulling comments from multiple posts
  • for each post, we were requesting get_comments(array('type' => 'comment'))
  • in wp-includes/comment-template.php , in function wp_list_comments(), code says:
    		if ( 'all' != $r['type'] ) {
    			if ( empty($wp_query->comments_by_type) )
    				$wp_query->comments_by_type = &separate_comments($wp_query->comments);
    			if ( empty($wp_query->comments_by_type[$r['type']]) )
    				return;
    			$_comments = $wp_query->comments_by_type[$r['type']];
    
    

unfortunately, since we were running that again and again, it would not recalculate $wp_query->comments_by_type each time.

I think that the function comments_template() in wp-includes/comment-template.php should have the following line added:

     $wp_query->comments_by_type = array();

right after the line where $wp_query->comments is set.

Attachments

14809.patch Download (757 bytes) - added by jakub.tyrcha 11 months ago.

Change History

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release
  • Keywords reporter-feedback added; needs-patch removed

I'm a bit confused here - if you were using get_comments() for each post and then supplying those as an argument to wp_list_comments(), the lines of code containing $wp_query->comments_by_type would never be invoked - they only get used if you don't supply your own list of comments.

Could you post the code you're using for get_comments() and wp_list_comments() in the loop?

@up as far as I understand, he didn't supply the comments as arguments, and the result of the get_comments() call was used

Note: See TracTickets for help on using tickets.