WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to display the "sticky" post in a section that is outside the "loop".

Can someone tell me how to do this?

share|improve this question
up vote 1 down vote accepted

I am using this query;

$sticky = get_option( 'sticky_posts' ); // Get all sticky posts
rsort( $sticky ); // Sort the stickies, latest first
$sticky = array_slice( $sticky, 0, 1 ); // Number of stickies to show
query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) ); // The query

if (have_posts() ) { while ( have_posts() ) : the_post(); ?>
    <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>

<?php endwhile;?>
<?php } else { echo ""; }?>

Hope it works for you too.. :)

share|improve this answer
Fine as for stickies, but query_posts() should not be used for secondary loops. get_posts() or new WP_Query should be used. – Rarst Jan 21 '11 at 6:00
 $last_sticky_post = get_post(end(get_option('sticky_posts')));
   the_title(); // standard loop here...

(this gets a single post)

use get_posts() with the 'include' => implode(',', get_option('sticky_posts')) argument to get all sticky posts (Martin's solution without array_slice will do the same).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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