Make WordPress Core

Changeset 52982


Ignore:
Timestamp:
03/23/2022 10:37:11 AM (2 years ago)
Author:
spacedmonkey
Message:

Query: Improved sticky post query

Ensure that the parameters update_post_meta_cache, update_post_term_cache, cache_results, suppress_filters and
lazy_load_term_meta that are passed to WP_Query, are also passed down to the secondary query used to get sticky
posts.

Props Spacedmonkey, peterwilsoncc, rehanali, uday17035.
Fixes #36907.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-query.php

    r52977 r52982  
    32613261                $stickies = get_posts(
    32623262                    array(
    3263                         'post__in'    => $sticky_posts,
    3264                         'post_type'   => $post_type,
    3265                         'post_status' => 'publish',
    3266                         'nopaging'    => true,
     3263                        'cache_results'          => $q['cache_results'],
     3264                        'lazy_load_term_meta'    => $q['lazy_load_term_meta'],
     3265                        'post__in'               => $sticky_posts,
     3266                        'post_type'              => $post_type,
     3267                        'post_status'            => 'publish',
     3268                        'suppress_filters'       => $q['suppress_filters'],
     3269                        'update_post_meta_cache' => $q['update_post_meta_cache'],
     3270                        'update_post_term_cache' => $q['update_post_term_cache'],
    32673271                    )
    32683272                );
  • trunk/tests/phpunit/tests/query/stickies.php

    r49603 r52982  
    55 *
    66 * @group query
     7 * @covers WP_Query::get_posts
    78 */
    89class Tests_Query_Stickies extends WP_UnitTestCase {
     
    105106        $q->set( 'post__not_in', array( self::$posts[8] ) );
    106107    }
     108
     109    /**
     110     * @ticket 36907
     111     */
     112    public function test_stickies_nest_query() {
     113        $filter = new MockAction();
     114        add_filter( 'posts_pre_query', array( $filter, 'filter' ), 10, 2 );
     115        $this->go_to( '/' );
     116        $filter_args       = $filter->get_args();
     117        $query_vars        = $filter_args[0][1]->query_vars;
     118        $sticky_query_vars = $filter_args[1][1]->query_vars;
     119
     120        $this->assertNotEmpty( $sticky_query_vars['posts_per_page'] );
     121        $this->assertSame( $query_vars['suppress_filters'], $sticky_query_vars['suppress_filters'] );
     122        $this->assertSame( $query_vars['update_post_meta_cache'], $sticky_query_vars['update_post_meta_cache'] );
     123        $this->assertSame( $query_vars['update_post_term_cache'], $sticky_query_vars['update_post_term_cache'] );
     124        $this->assertSame( $query_vars['lazy_load_term_meta'], $sticky_query_vars['lazy_load_term_meta'] );
     125        $this->assertSame( $query_vars['cache_results'], $sticky_query_vars['cache_results'] );
     126        $this->assertTrue( $sticky_query_vars['ignore_sticky_posts'] );
     127        $this->assertTrue( $sticky_query_vars['no_found_rows'] );
     128    }
    107129}
Note: See TracChangeset for help on using the changeset viewer.