How to Exclude Sticky Posts from the Loop in WordPress

Posted on March 11th, 2010 by in Themes | 3 Comments  
How to Exclude Sticky Posts from the Loop in WordPress

Sticky posts is one of the cool features that WordPress has, but sometimes you do not want to have sticky posts in your loop. In this article, we will show you how to completely exclude sticky posts from the loop in WordPress, and we will also show you how you can take away the sticky feature of the post, so it still shows in their natural order.

How to take away the Sticky Ability of the Post

When you are displaying most recent posts in a tab, you do not want the sticky posts to stay sticky. If you do not remove the sticky features, the recent posts area would be useless as all of your sticky posts will crowd this area. This is when query_posts feature comes in handy.

To do this you will need to change your loop to something like this:

<?php
query_posts('caller_get_posts=1');
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>

Completely exclude Sticky posts from the Loop

If you are using Sticky posts in a slider, then sometimes you might want to completely exclude your sticky posts from the loop. All what you have to do is edit your custom loop to match with this:

<?php
query_posts(array("post__not_in" =>get_option("sticky_posts")));
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>

This code will not display any sticky posts in the post loop.

Source: WP Codex

About

Editorial Staff at WPBeginner mainly Syed and David.

Post comment as twitter logo facebook logo
Sort: Newest | Oldest

it is working great, maybe just a bit too great: Now page 1 looks exactly like page 2 :(

You would have to add paging parameters in your loop as well for it to work. Sometimes adding queries like this breaks the pagination.

Tweets about us: