How to Display the Latest Sticky Posts in WordPress
WordPress has this very cool feature called stick posts. When you make a post sticky, it shows up above your new posts, but only if your theme is set to be that way. In this tutorial we will show you a trick that will let you display latest sticky posts anywhere in your WordPress theme.
Assuming that you have already created a custom page template and/or already have The Loop ready, paste the following code before the loop.
<?php
/* Get all sticky posts */
$sticky = get_option( 'sticky_posts' );/* Sort the stickies with the newest ones at the top */
rsort( $sticky );/* Get the 5 newest stickies (change 5 for a different number) */
$sticky = array_slice( $sticky, 0, 5 );/* Query sticky posts */
query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) );
?>
This code can very well be used in featured slider, or any other advanced feature that you would like to display on your site. This snippet is mostly geared toward a WordPress site that has a custom homepage or a magazine style look.
The credit to this code goes to Justin Tadlock and partially to Nathan Rice for coming up with the array slice solution.
Comments
2 Responses to “How to Display the Latest Sticky Posts in WordPress”Share Your Opinions
Tell us what you're thinking...
and if you want a pic to show with your comment, then get gravatar!
Please make sure that you have read our Comment Policy.










This is a website for beginners, can’t you dumb this down a little bit more?
We offer tutorials for all levels of WordPress Users. Beginners guide category and Showcase category are mostly for beginners. Theme editing, Tutorials, require prior knowledge. To make template changes, you need to know what the loop is. We provided the link in the article that explains what the loop is. Unfortunately, we cannot define what loop is in all of our articles because it is a concept that is a must know before you try to do any template editing.
We explained what each code in the query is doing. If you need individual help, you may use our contact form to contact us.