Question

I'm using pre_get_posts to adjust the number of posts displayed on my homepage.

function lifelounge_query_adjust( $query ) {
    if ( is_home() ) {
        set_query_var( 'posts_per_page', 12 );
        return;
    }
}
add_filter( 'pre_get_posts', 'lifelounge_query_adjust' );

But I am running into a problem with sticky posts. Basically, if I have any sticky posts, the query will display more than the 12 posts I have specified, because it will display 12 plus any sticky posts. I could, of course, ignore sticky posts:

function lifelounge_query_adjust( $query ) {
    if ( is_home() ) {
        set_query_var( 'posts_per_page', 1 );
        set_query_var( 'ignore_sticky_posts', 1 );
        return;
    }
}
add_filter( 'pre_get_posts', 'lifelounge_query_adjust' );

But I don't think this is ideal. I think the sticky posts should be included in the limit of 12 posts, and not added to the limit. That is what makes the most sense to me. Is there a way to achieve that? Have I made a face-palm-worthy error?

Pretty much a duplicate of: Sticky Posts & Posts Per Page but that was weirdly closed as too localized. I disagree, obviously because I'm looking for an answer, but also because it is a question of why WordPress doesn't seem to respect the posts_per_page limit if you are using sticky posts. If you want 12 posts per page you should get 12, not 13, which is what you would get if you had a single sticky post.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top