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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)