diff --git a/src/wp-includes/class-wp-query.php b/src/wp-includes/class-wp-query.php index 79bad783e1..ac0faa3edb 100644 --- a/src/wp-includes/class-wp-query.php +++ b/src/wp-includes/class-wp-query.php @@ -3260,10 +3260,14 @@ class WP_Query { if ( ! empty( $sticky_posts ) ) { $stickies = get_posts( array( - 'post__in' => $sticky_posts, - 'post_type' => $post_type, - 'post_status' => 'publish', - 'nopaging' => true, + 'cache_results' => $q['cache_results'], + 'lazy_load_term_meta' => $q['lazy_load_term_meta'], + 'post__in' => $sticky_posts, + 'post_type' => $post_type, + 'post_status' => 'publish', + 'suppress_filters' => $q['suppress_filters'], + 'update_post_meta_cache' => $q['update_post_meta_cache'], + 'update_post_term_cache' => $q['update_post_term_cache'], ) ); diff --git a/tests/phpunit/tests/query/stickies.php b/tests/phpunit/tests/query/stickies.php index e6d9d41f40..9ff07c63a4 100644 --- a/tests/phpunit/tests/query/stickies.php +++ b/tests/phpunit/tests/query/stickies.php @@ -4,6 +4,7 @@ * Tests related to sticky functionality in WP_Query. * * @group query + * @covers WP_Query::get_posts */ class Tests_Query_Stickies extends WP_UnitTestCase { public static $posts = array(); @@ -104,4 +105,25 @@ class Tests_Query_Stickies extends WP_UnitTestCase { public function set_post__not_in( $q ) { $q->set( 'post__not_in', array( self::$posts[8] ) ); } + + /** + * @ticket 36907 + */ + public function test_stickies_nest_query() { + $filter = new MockAction(); + add_filter( 'posts_pre_query', array( $filter, 'filter' ), 10, 2 ); + $this->go_to( '/' ); + $filter_args = $filter->get_args(); + $query_vars = $filter_args[0][1]->query_vars; + $sticky_query_vars = $filter_args[1][1]->query_vars; + + $this->assertNotEmpty( $sticky_query_vars['posts_per_page'] ); + $this->assertSame( $query_vars['suppress_filters'], $sticky_query_vars['suppress_filters'] ); + $this->assertSame( $query_vars['update_post_meta_cache'], $sticky_query_vars['update_post_meta_cache'] ); + $this->assertSame( $query_vars['update_post_term_cache'], $sticky_query_vars['update_post_term_cache'] ); + $this->assertSame( $query_vars['lazy_load_term_meta'], $sticky_query_vars['lazy_load_term_meta'] ); + $this->assertSame( $query_vars['cache_results'], $sticky_query_vars['cache_results'] ); + $this->assertTrue( $sticky_query_vars['ignore_sticky_posts'] ); + $this->assertTrue( $sticky_query_vars['no_found_rows'] ); + } }