Text Post

Count Published Sticky Posts in WordPress

get_option( 'sticky_posts' );

The problem with the above line of code, is that it also returns draft and trashed sticky posts. So to get the count of published posts only, you’ll need to query for it.

function get_sticky_posts_count() {
global $wpdb;
$sticky_posts = array_map( 'absint', (array) get_option('sticky_posts') );
return count($sticky_posts) > 0 ? $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( 1 ) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' AND ID IN (".implode(',', $sticky_posts).")" ) ) : 0;
}

get_sticky_posts_count();