Title: Excluding sticky posts using query_posts()
Last modified: August 19, 2016

---

# Excluding sticky posts using query_posts()

 *  [philpeter](https://wordpress.org/support/users/philpeter/)
 * (@philpeter)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/excluding-sticky-posts-using-query_posts/)
 * I had posted this on [another thread](http://wordpress.org/support/topic/208037?replies=23)
   but it’s now been marked resolved without an answer to my query…
 * I want to exclude the sticky posts from the loop and the previous thread had 
   this solution;
 *     ```
       query_posts(array(
       "post__not_in"	 =>	get_option("sticky_posts")
       ));
       ```
   
 * I’ve used this solution but it’s not working for me. I’m using it in the second
   loop in my home.php file, which is preceded by wp_reset_query().
 * The first loop uses this wp_query:
    query_posts(array(‘post__in’=>get_option(‘
   sticky_posts’)));
 * The second uses:
    query_posts(array(“post__not_in”=>get_option(“sticky_posts”)));
 * But I see the same (sticky) post as the first post produced by both loops. In
   date order it would be the third post.
 * Any idea why this wouldn’t work?

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/excluding-sticky-posts-using-query_posts/#post-1212839)
 * > I had posted this on another thread but it’s now been marked resolved without
   > an answer to my query…
 * It’s probably better you started another topic anyway…
 * As for ignoring sticky posts, the [query_posts() article shows](http://codex.wordpress.org/Template_Tags/query_posts)
 *     ```
       query_posts('caller_get_posts=1');
       ```
   
 *  Thread Starter [philpeter](https://wordpress.org/support/users/philpeter/)
 * (@philpeter)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/excluding-sticky-posts-using-query_posts/#post-1213035)
 * Yep, but caller_get_posts only returns sticky posts to the normal chronological
   order. I want all sticky posts to be excluded from the loop, which the query_posts()
   article says is possible by using
 *     ```
       query_posts(array(
       "post__not_in"	 =>	get_option("sticky_posts")
       ));
       ```
   
 * Problem is, that isn’t working!
 *  Thread Starter [philpeter](https://wordpress.org/support/users/philpeter/)
 * (@philpeter)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/excluding-sticky-posts-using-query_posts/#post-1213036)
 * According to [@wefixwp](http://twitter.com/wefixwp/statuses/5022493865), the 
   WP documentation on this is wrong.
 * To get around it, I’ve produced a normal, all-inclusive loop and wrapped all 
   the HTML code within it this IF statement:
    `if (!is_sticky())`
 * This stops the loop actually writing out the post if it is a sticky post. I guess
   it works but that documentation needs cleaning up.
 * Phil
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/excluding-sticky-posts-using-query_posts/#post-1213037)
 * This returned every post except for sticky posts:
 *     ```
       <?php
       $myposts = get_posts(array(
       'post__not_in' => get_option("sticky_posts"),
       'showposts' => -1
       ));
       echo "<pre>"; print_r($myposts); echo "</pre>";
       ?>
       ```
   
 *  [Chaz](https://wordpress.org/support/users/eternalskychaz/)
 * (@eternalskychaz)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/excluding-sticky-posts-using-query_posts/#post-1213069)
 * It seems as if this functionality should be coded into 2.9, but it seems that
   perhaps not as I am getting the Sticky Post showing up in my sidebar when I use
   the Recent Posts widget.
 * So, where do I plug this code in to get it to keep the Sticky Post from showing
   up in my sidebar?
 *  [merounds](https://wordpress.org/support/users/merounds/)
 * (@merounds)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/excluding-sticky-posts-using-query_posts/#post-1213072)
 * Using the above referenced code snippet does NOT exclude the sticky posts in 
   2.9.2. I noticed that the sticky part of the query algorithm sorts the results
   to move any stickies to the top, then does another search to add stickies that
   were not returned in the first search. I’ll guess that this second search does
   not honor the post__not_in argument.
 *  [itx](https://wordpress.org/support/users/itxitx/)
 * (@itxitx)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/excluding-sticky-posts-using-query_posts/#post-1213074)
 * it’s part of bug listed here:
    [http://core.trac.wordpress.org/ticket/11197](http://core.trac.wordpress.org/ticket/11197)
 * and will be resolved in wp 3.0 [http://core.trac.wordpress.org/changeset/14217](http://core.trac.wordpress.org/changeset/14217)

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Excluding sticky posts using query_posts()’ is closed to new replies.

## Tags

 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 7 replies
 * 5 participants
 * Last reply from: [itx](https://wordpress.org/support/users/itxitx/)
 * Last activity: [16 years, 1 month ago](https://wordpress.org/support/topic/excluding-sticky-posts-using-query_posts/#post-1213074)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
