On my Blog http://flattrendz.com/, I currently want to display the latest sticky post.

I used the code of http://justintadlock.com/archives/2009/03/28/get-the-latest-sticky-posts-in-wordpress

/* 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, 'caller_get_posts' => 1 ) );

<!-- BLOG BAR -->
<div class="blog_bar <?php echo $blog_bar_class; ?>">
    <div class="container">

        <div class="text-center">
            <h2 class="lead">

                <span><?php printf(__('From Our Blog', 'dot')); ?> </span>
                <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php printf(__('%s', 'dot'), get_the_title()); ?>"><?php the_title(); ?> <i class="icon-long-arrow-right"></i></a>

<!-- // BLOG BAR -->

<?php endwhile;?>
    else { }

 /* Restore original Post Data */

What I need to do is if there are posts marked as sticky post, then display just the latest sticky post, or else simply display the latest post.

1 Answer 1


I realized the issue. I missed the posts_per_page 'posts_per_page' => 1. Now it works.

  • Can you explain why that solved the problem?
    – s_ha_dum
    Jul 17, 2013 at 1:05
  • Hi, my assumption is that since the number of entries to return was mentioned in the sticky post array $sticky = array_slice( $sticky, 0, 2 ); and when there were no sticky posts, the number of regular posts displayed was based on the number of results I set to show per page from the settings in the backend. Adding posts_per_page fixed this by returning only 1 entry. Jul 17, 2013 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.