Make WordPress Core

Opened 10 years ago

Closed 8 years ago

Last modified 8 years ago

#31101 closed defect (bug) (fixed)

get_page_of_comment returns wrong page if comments are ordered with newest first

Reported by: pajtai's profile pajtai Owned by: rachelbaker's profile rachelbaker
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)

31101.patch (1.8 KB) - added by tyxla 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).
31101.diff (2.0 KB) - added by boonebgorges 8 years ago.

Download all attachments as: .zip

Change History (14)

@tyxla
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).

#2 @tyxla
10 years ago

  • Keywords has-patch added

This ticket was mentioned in Slack in #core-comments by rachelbaker. View the logs.


9 years ago

#4 @rachelbaker
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?

#5 @rachelbaker
9 years ago

  • Keywords dev-feedback added

This ticket was mentioned in Slack in #core-comments by rachelbaker. View the logs.


9 years ago

@boonebgorges
8 years ago

#7 @boonebgorges
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?

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.


8 years ago

#9 @rachelbaker
8 years ago

  • Owner set to rachelbaker
  • Status changed from new to reviewing

@boonebgorges I will test this today.

#10 @rachelbaker
8 years ago

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

In 38740:

Comments: Account for the comment_order option in get_page_of_comment().

Use the value of the comment_order setting to determine the date_query key to pass to WP_Comment_Query.
Fixes a bug where sites that had comments ordered "newest" first would have the incorrect page number returned.

Props tyxla, boonebgorges.
Fixes #31101.

#11 @boonebgorges
8 years ago

In 39663:

Ignore the 'comment_order' setting when determining comment pagination.

[38740] incorrectly introduced logic that changed a comment's page when
'comment_order' was set to 'desc'. This is in violation of the design
of the comment pagination system: a comment's page is designed not to
change when 'comment_order' or 'default_comment_page' are changed.
See #31101.

Props rachelbaker.
Fixes #39280.

#12 @boonebgorges
8 years ago

In 39664:

Ignore the 'comment_order' setting when determining comment pagination.

[38740] incorrectly introduced logic that changed a comment's page when
'comment_order' was set to 'desc'. This is in violation of the design
of the comment pagination system: a comment's page is designed not to
change when 'comment_order' or 'default_comment_page' are changed.
See #31101.

Merges [39663] to the 4.7 branch.

Props rachelbaker.
Fixes #39280.

Note: See TracTickets for help on using tickets.