Make WordPress Core


Ignore:
Timestamp:
03/07/2014 06:32:40 PM (11 years ago)
Author:
wonderboymusic
Message:

When setting posts_per_page in WP_Query::get_posts(), check for is_feed() in the same place where posts_per_page is set when it is not already set. Previously, when is_feed() was true, posts_per_page would be arbitrarily overwritten. This fix allows posts_per_page to be set during pre_get_posts when is_feed() is true and not be overwritten.

Adds unit test.

Props wokamoto.
Fixes #25380.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/query.php

    r27304 r27455  
    8888        $this->assertTrue( $query->get( 'nonexistent', true ) );
    8989    }
     90
     91    /**
     92     * @ticket 25380
     93     */
     94    function test_pre_posts_per_page() {
     95        $this->factory->post->create_many( 10 );
     96
     97        add_action( 'pre_get_posts', array( $this, 'filter_posts_per_page' ) );
     98
     99        $this->go_to( get_feed_link() );
     100
     101        $this->assertEquals( 30, get_query_var( 'posts_per_page' ) );
     102    }
     103
     104    function filter_posts_per_page( &$query ) {
     105        $query->set( 'posts_per_page', 30 );
     106    }
    90107}
Note: See TracChangeset for help on using the changeset viewer.