WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#34771 closed defect (bug) (wontfix)

Comment ordering is not applying the order by latest or newest filter.

Reported by: alexvandervegt Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.3.1
Component: Comments Keywords: reporter-feedback
Focuses: Cc:

Description

The comment ordering does not listen to the option in the wp-admin for it.

It has probably to do with line 1181 of wp-includes/comment-template.php (WP 4.3.1)

'orderby' => 'comment_date_gmt',

No filter applied here...

Change History (3)

#1 @boonebgorges
6 years ago

  • Focuses ui accessibility removed
  • Keywords reporter-feedback added

@alexvandervegt In versions 4.3.1 and earlier, comment ordering is handled by the Walker_Comment class; see wp_list_comments(). Are you running any plugins that modify the way comments are displayed? What theme are you using?

This logic has been entirely rewritten for version 4.4.0. Are you able to see whether the issue remains on the latest 4.4 beta, or using WP trunk?

#2 @alexvandervegt
6 years ago

When i have a look at:

https://github.com/WordPress/WordPress/blob/master/wp-includes/comment-template.php

Line 1284:

'orderby' => 'comment_date_gmt',
'order' => 'ASC',

The issue is still present. The problem will accure when you build the comments.php in HTML and PHP without the comment walker. But just a foreach loop on the $comments.

When i think about it something like this would be a much better better solution:

'orderby' => 'comment_date_gmt',
'order' => apply_filters( 'comments_order', 'ASC' ),

The default function for the comments_order should proces the admin option already and we are also able to overrule when needed.

Same goes for the orderby, overruling here should also be desirable.

#3 @boonebgorges
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Thanks for the clarification, @alexvandervegt. I'd say that looping over $comments is a technique that we can't officially support in all cases. WP can't enforce things like threading and pagination if you don't use a Walker-like tool for building markup.

However! This has all been rewritten for 4.4. The comment query in comments_template() still grabs comments with orderby => 'comment_date_gmt' and order => 'ASC', but it does most of the pagination work before hitting the Walker in wp_list_comments(). See #5809.

I'd suggest that, if you plan to loop over $comments in comments.php, you do some preprocessing of those comments to ensure the proper order, threading, etc. The comments_array filter will work well for this. However, if you have a good reason for preferring to do it with a filter, you may want to try a pre_get_comments callback.

Thanks for the ticket!

Note: See TracTickets for help on using tickets.