Posted By

gd6d on 10/28/09


Tagged

wordpress sticky posts


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

raz


Get the latest sticky posts in WordPress


 / Published in: PHP
 

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

  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. ?>

Report this snippet  

You need to login to post a comment.