Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
WordPress Plugins
View all Guides

How to Exclude Sticky Posts from the Loop in WordPress

Last updated on by
Special WordPress Hosting offer for WPBeginner Readers
How to Exclude Sticky Posts from the Loop in WordPress

Sticky Posts are a great way to highlight your featured content. However, there are certain places on your website where you don’t need sticky posts to be on the top. WordPress can not guess this so you need to explicitly tell WordPress to exclude sticky posts from a custom 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 feature, the recent posts area would be useless as all your sticky posts will crowd this area. This is where query_posts feature comes in handy.

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

$args = array(
	'posts_per_page' => 10,
	'ignore_sticky_posts' => 1
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();

This code ignores that a post is sticky and shows the posts in the normal order. Using this code your sticky posts will appear in the loop, however they will not be placed on the top.

Sticky posts displayed in normal order

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:

$the_query = new WP_Query( array( 'post__not_in' => get_option( 'sticky_posts' ) ) );
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();

This code will not display any sticky posts in the post loop. For more tips on modifying WordPress themes, check out our WordPress Theme Cheat Sheet for beginners.

Source: WP Codex

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »


  1. Sam says:

    Your code just causes my links to break and i’m not sure why

  2. Stephen says:

    I am having a problem that the one “sticky” post shows up as the first “featured” post so there is the same article listed twice in succession. Any help would be great.

  3. Kyle Shevlin says:

    Don’t know if this happened for anyone else, but using this broke the pagination. My next page of posts would be a repeat of the first page. If this happened to anyone else, do you have a fix?

  4. Agus Almaula says:

    Thank you so much, just because i am totally wpBeginner i came to this site and my WP development solved.


  5. Rut says:

    Where do I paste this peace of code? I constantly get errors…

  6. Daniel Lemes says:

    Both methods broke my pagination (page links still there, but load always the same posts), any idea on it?

  7. Rohit Tripathi says:

    This is really great. One place where you don’t need this is when creating a custom sidebar widget to display recent posts.


  8. Kyle Shevlin says:

    Is there any reason that adding this would remove the functionality of archives and tag cloud links? I, too, am trying to exclude sticky posts from my main blog loop using one loop to operate a featured section and a second to operate everything else. The trouble I’m having comes when I click on links in an archive section or tag cloud. It redirects me back to my first page again. When I remove this exclusionary code, it works just fine. Can’t figure this one out.

  9. chris mccoy says:

    you can also use pre_get_posts so you dont have to alter your main loop.

    $query->set(‘post__not_in’, get_option(‘sticky_posts’));

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.