diff --git a/src/wp-includes/class-wp-comment-query.php b/src/wp-includes/class-wp-comment-query.php index f6a17d7687..ef8b6d545b 100644 --- a/src/wp-includes/class-wp-comment-query.php +++ b/src/wp-includes/class-wp-comment-query.php @@ -996,6 +996,8 @@ class WP_Comment_Query { $parent_query_args['parent__in'] = $uncached_parent_ids; $parent_query_args['no_found_rows'] = true; $parent_query_args['hierarchical'] = false; + $parent_query_args['offset'] = 0; + $parent_query_args['number'] = 0; $level_comments = get_comments( $parent_query_args ); diff --git a/tests/phpunit/tests/comment/query.php b/tests/phpunit/tests/comment/query.php index 4710d64001..ff4e3aced3 100644 --- a/tests/phpunit/tests/comment/query.php +++ b/tests/phpunit/tests/comment/query.php @@ -2543,6 +2543,40 @@ class Tests_Comment_Query extends WP_UnitTestCase { $this->assertEqualSets( $q1_ids, $q2_ids ); } + /** + * @ticket 37966 + * @ticket 37696 + */ + public function test_fill_hierarchy_should_disregard_offset_and_number() { + $c0 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); + $c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); + $c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_parent' => $c1 ) ); + $c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); + $c4 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_parent' => $c3 ) ); + $c5 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_parent' => $c3 ) ); + + $q = new WP_Comment_Query(); + $found = $q->query( array( + 'orderby' => 'comment_date_gmt', + 'order' => 'ASC', + 'status' => 'approve', + 'post_id' => self::$post_id, + 'no_found_rows' => false, + 'hierarchical' => 'threaded', + 'number' => 2, + 'offset' => 1, + ) ); + + + $found_1 = $found[ $c1 ]; + $children_1 = $found_1->get_children(); + $this->assertEqualSets( array( $c2 ), array_keys( $children_1 ) ); + + $found_3 = $found[ $c3 ]; + $children_3 = $found_3->get_children(); + $this->assertEqualSets( array( $c4, $c5 ), array_keys( $children_3 ) ); + } + /** * @ticket 27571 */