Get the latest sticky posts in WordPress


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. /* Get all sticky posts */
  3. $sticky = get_option( 'sticky_posts' );
  4.  
  5. /* Sort the stickies with the newest ones at the top */
  6. rsort( $sticky );
  7.  
  8. /* Get the 2 newest stickies (change 2 for a different number) */
  9. $sticky = array_slice( $sticky, 0, 2 );
  10.  
  11. /* Query sticky posts */
  12. query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) );
  13. ?>

URL: http://justintadlock.com/archives/2009/03/28/get-the-latest-sticky-posts-in-wordpress

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.