Make WordPress Core

Changeset 52990


Ignore:
Timestamp:
03/25/2022 09:54:52 AM (3 years ago)
Author:
spacedmonkey
Message:

Query: Ensure that sticky post query returns all sticky posts.

Ensure that the posts_per_page parameter submit to sticky post query matches the number of sticky posts requested.

Follow-up to [52982]

Props Spacedmonkey, peterwilsoncc.
See #36907.

Location:
trunk
Files:
2 edited

Legend:

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

    r52985 r52990  
    32643264                        'post_type'              => $post_type,
    32653265                        'post_status'            => 'publish',
     3266                        'posts_per_page'         => count( $sticky_posts ),
    32663267                        'suppress_filters'       => $q['suppress_filters'],
    32673268                        'cache_results'          => $q['cache_results'],
  • trunk/tests/phpunit/tests/query/stickies.php

    r52985 r52990  
    127127        $this->assertTrue( $sticky_query_vars['no_found_rows'] );
    128128    }
     129
     130    /**
     131     * @ticket 36907
     132     */
     133    public function test_stickies_should_limit_query() {
     134        $sticky_count = 6;
     135        $post_date    = gmdate( 'Y-m-d H:i:s', time() - 10000 );
     136        $post_ids     = self::factory()->post->create_many( $sticky_count, array( 'post_date' => $post_date ) );
     137        add_filter(
     138            'pre_option_sticky_posts',
     139            function () use ( $post_ids ) {
     140                return $post_ids;
     141            }
     142        );
     143
     144        $filter = new MockAction();
     145        add_filter( 'posts_pre_query', array( $filter, 'filter' ), 10, 2 );
     146        $this->go_to( '/' );
     147        $filter_args       = $filter->get_args();
     148        $sticky_query_vars = $filter_args[1][1]->query_vars;
     149
     150        $this->assertSame( $sticky_query_vars['posts_per_page'], $sticky_count );
     151    }
    129152}
Note: See TracChangeset for help on using the changeset viewer.