Include sticky posts in ‘Blog pages show at most’ X number of posts?

You can use this code:

add_action( 'pre_get_posts', 'exclude_sticky' );

function exclude_sticky( $query ) {
    if ($query->get('paged') == 0) {
        $sticky = get_option('sticky_posts');
        $num = get_option('posts_per_page');
        $extras = $num - count($sticky);
        $query->set( 'posts_per_page', $extras );
    }

}

Leave a Comment