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.

git-svn-id: https://develop.svn.wordpress.org/trunk@38740 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Rachel Baker
2016-10-06 17:41:51 +00:00
parent 7cc095a1a0
commit 9dd9880600
2 changed files with 25 additions and 1 deletions

View File

@@ -918,6 +918,12 @@ function get_page_of_comment( $comment_ID, $args = array() ) {
if ( $args['max_depth'] > 1 && 0 != $comment->comment_parent )
return get_page_of_comment( $comment->comment_parent, $args );
if ( 'desc' === get_option( 'comment_order' ) ) {
$compare = 'after';
} else {
$compare = 'before';
}
$comment_args = array(
'type' => $args['type'],
'post_id' => $comment->comment_post_ID,
@@ -928,7 +934,7 @@ function get_page_of_comment( $comment_ID, $args = array() ) {
'date_query' => array(
array(
'column' => "$wpdb->comments.comment_date_gmt",
'before' => $comment->comment_date_gmt,
$compare => $comment->comment_date_gmt,
)
),
);