Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/wp-includes/class-wp-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -3365,7 +3365,8 @@ public function get_posts() {

if ( null === $this->posts ) {
$split_the_query = (
$is_unfiltered_query
1 !== $query_vars['posts_per_page']
&& $is_unfiltered_query
&& (
wp_using_ext_object_cache()
|| ( ! empty( $limits ) && $query_vars['posts_per_page'] < 500 )
Expand Down
30 changes: 30 additions & 0 deletions tests/phpunit/tests/post/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -809,9 +809,39 @@ public function test_split_the_query_object_cache() {
)
);

remove_filter( 'split_the_query', array( $filter, 'filter' ) );

$this->assertSame( (bool) wp_using_ext_object_cache(), $filter->get_args()[0][0] );
}

/**
* @ticket 57416
*
* @dataProvider data_split_the_query_should_be_disabled_when_posts_per_page_is_one
*/
public function test_split_the_query_should_be_disabled_when_posts_per_page_is_one( $posts_per_page, $expected ) {
$filter = new MockAction();
add_filter( 'split_the_query', array( $filter, 'filter' ) );

$q = new WP_Query(
array(
'posts_per_page' => $posts_per_page,
'cache_results' => false,
)
);

remove_filter( 'split_the_query', array( $filter, 'filter' ) );

$this->assertSame( $expected, $filter->get_args()[0][0] );
}

public function data_split_the_query_should_be_disabled_when_posts_per_page_is_one() {
return array(
'one post' => array( 1, false ),
'two posts' => array( 2, true ),
);
}

/**
* @ticket 56841
*/
Expand Down
Loading