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
This commit is contained in:
parent
818bf7c6af
commit
bc968895cc
|
@ -2248,8 +2248,13 @@ class WP_Query {
|
||||||
$q['post_type'] = '';
|
$q['post_type'] = '';
|
||||||
}
|
}
|
||||||
$post_type = $q['post_type'];
|
$post_type = $q['post_type'];
|
||||||
if ( !isset($q['posts_per_page']) || $q['posts_per_page'] == 0 )
|
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' );
|
$q['posts_per_page'] = get_option( 'posts_per_page' );
|
||||||
|
}
|
||||||
|
}
|
||||||
if ( isset($q['showposts']) && $q['showposts'] ) {
|
if ( isset($q['showposts']) && $q['showposts'] ) {
|
||||||
$q['showposts'] = (int) $q['showposts'];
|
$q['showposts'] = (int) $q['showposts'];
|
||||||
$q['posts_per_page'] = $q['showposts'];
|
$q['posts_per_page'] = $q['showposts'];
|
||||||
|
@ -2264,7 +2269,6 @@ class WP_Query {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( $this->is_feed ) {
|
if ( $this->is_feed ) {
|
||||||
$q['posts_per_page'] = get_option('posts_per_rss');
|
|
||||||
$q['nopaging'] = false;
|
$q['nopaging'] = false;
|
||||||
}
|
}
|
||||||
$q['posts_per_page'] = (int) $q['posts_per_page'];
|
$q['posts_per_page'] = (int) $q['posts_per_page'];
|
||||||
|
|
Loading…
Reference in New Issue