From bc968895cc611987dd285470682c7f266709897c Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Fri, 7 Mar 2014 18:33:15 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@27455 git-svn-id: http://core.svn.wordpress.org/trunk@27301 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/query.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/wp-includes/query.php b/wp-includes/query.php index d251ef1763..e8c95caf68 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -2248,8 +2248,13 @@ class WP_Query { $q['post_type'] = ''; } $post_type = $q['post_type']; - if ( !isset($q['posts_per_page']) || $q['posts_per_page'] == 0 ) - $q['posts_per_page'] = get_option('posts_per_page'); + 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 ( isset($q['showposts']) && $q['showposts'] ) { $q['showposts'] = (int) $q['showposts']; $q['posts_per_page'] = $q['showposts']; @@ -2264,7 +2269,6 @@ class WP_Query { } } if ( $this->is_feed ) { - $q['posts_per_page'] = get_option('posts_per_rss'); $q['nopaging'] = false; } $q['posts_per_page'] = (int) $q['posts_per_page'];