Free Wordpress Blog Setup

How to Exclude Sticky Posts from the Loop in WordPress

By Editorial Staff in Themes
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

What Next?

Digg it
Save This Page
Subscribe to WPBeginner
Stumble it
Free Wordpress Blog Setup

Comments

No Responses to “How to Exclude Sticky Posts from the Loop 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.

Due to high volume of request from our readers, we are adding this feature that allows you to stay updated with this post's comments without having to participate in the discussion even though we would love your input as always. Don't worry we hate SPAM just as much as you do, so you will never receive any SPAM messages from our site and that's our promise to you.

Subscribe without commenting

Close Bar