mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-05-29 15:44:27 +00:00
Improve pagination internals in WP_Comment_Query.
`WP_Comment_Query` will now report the total number of comments matching the query params (`comments_found`), as well as the total number of pages required to display these comments (`max_num_pages`). Because `SQL_CALC_FOUND_ROWS` queries can introduce a lot of overhead in some cases, we disable the feature by default. Pass `no_found_rows=false` to `WP_Comment_Query` to enable the count. (We use the negative parameter name 'no_found_rows' for parity with `WP_Query`.) Props wonderboymusic, boonebgorges. See #8071. git-svn-id: https://develop.svn.wordpress.org/trunk@34544 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1873,4 +1873,51 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
$this->assertEquals( array( $c2, $c3 ), $ids->comments );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 8071
|
||||
*/
|
||||
public function test_no_found_rows_should_default_to_true() {
|
||||
$comments = $this->factory->comment->create_many( 3, array( 'comment_post_ID' => $this->post_id ) );
|
||||
|
||||
$q = new WP_Comment_Query( array(
|
||||
'post_id' => $this->post_id,
|
||||
'number' => 2,
|
||||
) );
|
||||
|
||||
$this->assertEquals( 0, $q->found_comments );
|
||||
$this->assertEquals( 0, $q->max_num_pages );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 8071
|
||||
*/
|
||||
public function test_should_respect_no_found_rows_true() {
|
||||
$comments = $this->factory->comment->create_many( 3, array( 'comment_post_ID' => $this->post_id ) );
|
||||
|
||||
$q = new WP_Comment_Query( array(
|
||||
'post_id' => $this->post_id,
|
||||
'number' => 2,
|
||||
'no_found_rows' => true,
|
||||
) );
|
||||
|
||||
$this->assertEquals( 0, $q->found_comments );
|
||||
$this->assertEquals( 0, $q->max_num_pages );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 8071
|
||||
*/
|
||||
public function test_should_respect_no_found_rows_false() {
|
||||
$comments = $this->factory->comment->create_many( 3, array( 'comment_post_ID' => $this->post_id ) );
|
||||
|
||||
$q = new WP_Comment_Query( array(
|
||||
'post_id' => $this->post_id,
|
||||
'number' => 2,
|
||||
'no_found_rows' => false,
|
||||
) );
|
||||
|
||||
$this->assertEquals( 3, $q->found_comments );
|
||||
$this->assertEquals( 2, $q->max_num_pages );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user