Beginner's Guide for WordPress / Start your WordPress Blog in minutes

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

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit – a collection of WordPress related products and resources that every professional should have!

Reader Interactions

12 CommentsLeave a Reply

  1. I am having similar issue with the broken pagination when removing the sticky post, does anyone has a fix thanks

  2. 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. 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. Thank you so much, just because i am totally wpBeginner i came to this site and my WP development solved.


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

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


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

  8. 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’));

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.