mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-03-31 18:54:29 +00:00
Query: set_found_posts() must run immediately after main query.
If not run immediately after, the `SELECT FOUND_ROWS()` query might refer to a different query, such as the one used to populate the post cache for a split query. Introduced in [37692]. Fixes #36687. git-svn-id: https://develop.svn.wordpress.org/trunk@37721 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -447,4 +447,92 @@ class Tests_Post_Query extends WP_UnitTestCase {
|
||||
public function filter_found_posts( $posts ) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 36687
|
||||
*/
|
||||
public function test_set_found_posts_fields_ids() {
|
||||
register_post_type( 'wptests_pt' );
|
||||
|
||||
$posts = self::factory()->post->create_many( 2, array( 'post_type' => 'wptests_pt' ) );
|
||||
|
||||
foreach ( $posts as $p ) {
|
||||
clean_post_cache( $p );
|
||||
}
|
||||
|
||||
$q = new WP_Query( array(
|
||||
'post_type' => 'wptests_pt',
|
||||
'posts_per_page' => 1,
|
||||
'fields' => 'ids',
|
||||
) );
|
||||
|
||||
$this->assertEquals( 2, $q->found_posts );
|
||||
$this->assertEquals( 2, $q->max_num_pages );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 36687
|
||||
*/
|
||||
public function test_set_found_posts_fields_idparent() {
|
||||
register_post_type( 'wptests_pt' );
|
||||
|
||||
$posts = self::factory()->post->create_many( 2, array( 'post_type' => 'wptests_pt' ) );
|
||||
foreach ( $posts as $p ) {
|
||||
clean_post_cache( $p );
|
||||
}
|
||||
|
||||
$q = new WP_Query( array(
|
||||
'post_type' => 'wptests_pt',
|
||||
'posts_per_page' => 1,
|
||||
'fields' => 'id=>parent',
|
||||
) );
|
||||
|
||||
$this->assertEquals( 2, $q->found_posts );
|
||||
$this->assertEquals( 2, $q->max_num_pages );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 36687
|
||||
*/
|
||||
public function test_set_found_posts_fields_split_the_query() {
|
||||
register_post_type( 'wptests_pt' );
|
||||
|
||||
$posts = self::factory()->post->create_many( 2, array( 'post_type' => 'wptests_pt' ) );
|
||||
foreach ( $posts as $p ) {
|
||||
clean_post_cache( $p );
|
||||
}
|
||||
|
||||
add_filter( 'split_the_query', '__return_true' );
|
||||
$q = new WP_Query( array(
|
||||
'post_type' => 'wptests_pt',
|
||||
'posts_per_page' => 1,
|
||||
) );
|
||||
remove_filter( 'split_the_query', '__return_true' );
|
||||
|
||||
$this->assertEquals( 2, $q->found_posts );
|
||||
$this->assertEquals( 2, $q->max_num_pages );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 36687
|
||||
*/
|
||||
public function test_set_found_posts_fields_not_split_the_query() {
|
||||
register_post_type( 'wptests_pt' );
|
||||
|
||||
$posts = self::factory()->post->create_many( 2, array( 'post_type' => 'wptests_pt' ) );
|
||||
foreach ( $posts as $p ) {
|
||||
clean_post_cache( $p );
|
||||
}
|
||||
|
||||
// ! $split_the_query
|
||||
add_filter( 'split_the_query', '__return_false' );
|
||||
$q = new WP_Query( array(
|
||||
'post_type' => 'wptests_pt',
|
||||
'posts_per_page' => 1,
|
||||
) );
|
||||
remove_filter( 'split_the_query', '__return_false' );
|
||||
|
||||
$this->assertEquals( 2, $q->found_posts );
|
||||
$this->assertEquals( 2, $q->max_num_pages );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user