I'm trying to limit the number of posts on the homepage but is_home() and is_frontpage() always seem to return true (even when I'm browsing /page/2/, /page/3/ and so on).
I've basically duplicated the twenty fifteen theme and trying to make my own based on that one. I deleted every function in functions.php (also removed any calls to those functions) and currently I only have this function in there:
add_action( 'pre_get_posts', 'limit_frontpage_posts' );
function limit_frontpage_posts( $query ) {
if ( is_front_page() || is_home() ){
$query->set( 'posts_per_page', 1 );
}
return $query;
}
Basically I want one post on the frontpage and on every other page whatever limit has been set in the admin panel. The code above is showing only one post on every page. Any idea's what's going wrong?
Settings -> Reading
have you set a homepage or is the homepage also your blog ( which is default functionality )? It would also be best to test against the current query by prefixing your conditional statements with$query->is_front_page()
and$query->is_main_query()
so it doesn't run the filter on all queries on the front page.