Support » Fixing WordPress » Excluding sticky posts using query_posts()

  • I had posted this on another thread 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;

    "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:

    The second uses:

    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)
  • 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


    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

    "post__not_in"	 =>	get_option("sticky_posts")

    Problem is, that isn’t working!

    According to @wefixwp, 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.


    This returned every post except for sticky posts:

    $myposts = get_posts(array(
    'post__not_in' => get_option("sticky_posts"),
    'showposts' => -1
    echo "<pre>"; print_r($myposts); echo "</pre>";



    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?

    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.

    it’s part of bug listed here:

    and will be resolved in wp 3.0

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Excluding sticky posts using query_posts()’ is closed to new replies.