diff --git a/src/wp-includes/comment-functions.php b/src/wp-includes/comment-functions.php index c58588e924..67bd33e677 100644 --- a/src/wp-includes/comment-functions.php +++ b/src/wp-includes/comment-functions.php @@ -877,7 +877,7 @@ function get_page_of_comment( $comment_ID, $args = array() ) { $comment_args = array( 'type' => $args['type'], - 'post_ID' => $comment->comment_post_ID, + 'post_id' => $comment->comment_post_ID, 'fields' => 'ids', 'status' => 'approve', 'date_query' => array( diff --git a/tests/phpunit/tests/comment/getPageOfComment.php b/tests/phpunit/tests/comment/getPageOfComment.php index d749076a86..78e53d5d44 100644 --- a/tests/phpunit/tests/comment/getPageOfComment.php +++ b/tests/phpunit/tests/comment/getPageOfComment.php @@ -171,4 +171,24 @@ class Tests_Comment_GetPageOfComment extends WP_UnitTestCase { $this->assertEquals( 2, get_page_of_comment( $c1, array( 'per_page' => 2 ) ) ); } + + /** + * @ticket 34057 + */ + public function test_query_should_be_limited_to_comments_on_the_proper_post() { + $posts = $this->factory->post->create_many( 2 ); + + $now = time(); + $comments_0 = $comments_1 = array(); + for ( $i = 0; $i < 5; $i++ ) { + $comments_0[] = $this->factory->comment->create( array( 'comment_post_ID' => $posts[0], 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - ( $i * 60 ) ) ) ); + $comments_1[] = $this->factory->comment->create( array( 'comment_post_ID' => $posts[1], 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - ( $i * 60 ) ) ) ); + } + + $found_0 = get_page_of_comment( $comments_0[0], array( 'per_page' => 2 ) ); + $this->assertEquals( 3, $found_0 ); + + $found_1 = get_page_of_comment( $comments_1[1], array( 'per_page' => 2 ) ); + $this->assertEquals( 2, $found_1 ); + } }