From dfc11a170b42b33648fbc7ac8d057fab154a248c Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Fri, 7 Mar 2014 18:58:33 +0000 Subject: [PATCH] On second thought, allow `posts_per_rss` to be set in `pre_get_posts` to override the `posts_per_rss` option. There are backwards compatibility concerns otherwise. Props nacin. Partially reverts [27455]. Updates the unit test. See #25380. git-svn-id: https://develop.svn.wordpress.org/trunk@27456 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/query.php | 14 ++++++++------ tests/phpunit/tests/query.php | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/wp-includes/query.php b/src/wp-includes/query.php index e8c95caf68..0f7e104f99 100644 --- a/src/wp-includes/query.php +++ b/src/wp-includes/query.php @@ -2248,12 +2248,8 @@ class WP_Query { $q['post_type'] = ''; } $post_type = $q['post_type']; - if ( ! isset( $q['posts_per_page'] ) || $q['posts_per_page'] == 0 ) { - if ( $this->is_feed ) { - $q['posts_per_page'] = get_option( 'posts_per_rss' ); - } else { - $q['posts_per_page'] = get_option( 'posts_per_page' ); - } + if ( empty( $q['posts_per_page'] ) ) { + $q['posts_per_page'] = get_option( 'posts_per_page' ); } if ( isset($q['showposts']) && $q['showposts'] ) { $q['showposts'] = (int) $q['showposts']; @@ -2269,6 +2265,12 @@ class WP_Query { } } if ( $this->is_feed ) { + // This overrides posts_per_page. + if ( ! empty( $q['posts_per_rss'] ) ) { + $q['posts_per_page'] = $q['posts_per_rss']; + } else { + $q['posts_per_page'] = get_option( 'posts_per_rss' ); + } $q['nopaging'] = false; } $q['posts_per_page'] = (int) $q['posts_per_page']; diff --git a/tests/phpunit/tests/query.php b/tests/phpunit/tests/query.php index 98a66dbb3a..6207d85219 100644 --- a/tests/phpunit/tests/query.php +++ b/tests/phpunit/tests/query.php @@ -102,6 +102,6 @@ class Tests_Query extends WP_UnitTestCase { } function filter_posts_per_page( &$query ) { - $query->set( 'posts_per_page', 30 ); + $query->set( 'posts_per_rss', 30 ); } } \ No newline at end of file