I’d like to display the most two recent published sticky posts by modifying the primary loop. A simple affair with the following loop.
However, if I schedule a sticky post to be published in the future, the loop fails – only displaying one sticky post. It’s like it can see that there is a new sticky post, but since it’s scheduled it does not display. And then the loop thinks it’s already displayed the two posts I requested. Any ideas?
/* Get all sticky posts */
$sticky = get_option( 'sticky_posts' );
/* Sort the stickies with the newest ones at the top */
rsort( $sticky );
/* Get the 2 newest stickies (change 2 for a different number) */
$sticky = array_slice( $sticky, 0, 2 );
/* Query sticky posts */
query_posts( array( 'post__in' => $sticky, 'ignore_sticky_posts' => 1 ) );
while (have_posts()) : the_post();
the_title();
the_excerpt();
endwhile();
/* Continue with Page Template */