mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-01 11:14:36 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@27455 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -87,4 +87,21 @@ class Tests_Query extends WP_UnitTestCase {
|
||||
$this->assertFalse( $query->get( 'nonexistent', false ) );
|
||||
$this->assertTrue( $query->get( 'nonexistent', true ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 25380
|
||||
*/
|
||||
function test_pre_posts_per_page() {
|
||||
$this->factory->post->create_many( 10 );
|
||||
|
||||
add_action( 'pre_get_posts', array( $this, 'filter_posts_per_page' ) );
|
||||
|
||||
$this->go_to( get_feed_link() );
|
||||
|
||||
$this->assertEquals( 30, get_query_var( 'posts_per_page' ) );
|
||||
}
|
||||
|
||||
function filter_posts_per_page( &$query ) {
|
||||
$query->set( 'posts_per_page', 30 );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user