#31101 closed defect (bug) (fixed)
get_page_of_comment returns wrong page if comments are ordered with newest first
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.7 | Priority: | normal |
Severity: | normal | Version: | 4.1 |
Component: | Comments | Keywords: | has-patch needs-testing |
Focuses: | Cc: |
Description
Set newest to be at top of comments.
Now the newest comments should be on page 1, but the last page is still returned, becuase the sql statement counts the number of older comments still, since the less than sign is hard coded:
// The following should have the less than sign be greater than if newest comments are shown first: $oldercoms = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = 0 AND comment_approved = '1' AND comment_date_gmt < '%s'" . $comtypewhere, $comment->comment_post_ID, $comment->comment_date_gmt ) );
Attachments (2)
Change History (14)
@
10 years ago
Using the right comparison operator when looking for older/newer comments in get_page_of_comment()
(depending on the comment order in Settings -> Discussion).
This ticket was mentioned in Slack in #core-comments by rachelbaker. View the logs.
9 years ago
#4
@
9 years ago
@boonebgorges Came across this ticket while bug gardening, it looks as though get_page_of_comment()
does not take get_option('comment_order');
into account.
In wp_list_comments()
the page variable is handled with a special reverse_top_level
argument, but I don't see the comment_order
option considered anywhere else. Do you know if there is a reason for this?
This ticket was mentioned in Slack in #core-comments by rachelbaker. View the logs.
9 years ago
#7
@
8 years ago
- Keywords needs-testing added; dev-feedback removed
- Milestone changed from Awaiting Review to 4.7
It appears to me that 'comment_order' has never been considered in get_page_of_comment()
, even before the pagination rewrite in 4.4. As far as I can see, this is an oversight. The oversight can probably be explained by the fact that get_page_of_comment()
is only used in core in get_comment_link()
, and in that case only when the page of the comment can't be inferred by context. So the bug would rear its head rarely.
31101.diff adds the necessary logic, and it appears to fix the bug in my testing. Can others confirm?
Related: #8973, #13939, #18603.