WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The following snippet is from a sidebar widget that lists "recent posts". Since its on the home page and I feature my lastest sticky post prominently on that page, I want to skip over the sticky in this loop. However, the post_not_in=sticky_posts has no effect.

    $the_query = new WP_Query("showposts=$number&offset=1&order=ASC&post_not_in=sticky_posts");

    while ($the_query->have_posts()) : $the_query->the_post();
        $do_not_duplicate = $post->ID; ?>
share|improve this question
up vote 2 down vote accepted

I took @tnorthcutt's answer from WordPress' Codex on query_posts() about Sticky Parameters and created a tandalone example you can drop as test.php into your website's root and see it run by navigating to a URL like this, with your domain substituted:


Some notes on the code; I had to use an array equivalent of the query string you passed to WP_Query() because the post__no_in argument can't be passed in as a comma delimited string (not sure why, probably an oversight?).

Also I wanted to make sure you know that starting with an offset=1 (instead of offset=0) means you'll be excluding the first post that otherwise would be returned by the query. Of course you'll still get the number of posts specified by $number assuming you have that many applicable posts +1. So here's the code:

include "wp-load.php";

$number = 5;

$the_query = new WP_Query(array(
  'showposts' => $number,
  'offset' => 1,  // This will cause the query to skip over first post
  'order' => 'ASC',
  'post__not_in' => get_option("sticky_posts"),
while ($the_query->have_posts()) : $the_query->the_post();
share|improve this answer
Thanks Mike. Great solution and thoughtful explanation. I really appreciate it. Sorry it took so long to respond :) – Scott B Aug 31 '10 at 18:13
The post__not_in question is answered here: wordpress.stackexchange.com/questions/127/… – Dan Gayle Sep 10 '10 at 19:25
@Dan Gayle: Good Catch. – MikeSchinkel Sep 10 '10 at 20:58

If you want to exclude all sticky posts from a query, use

query_posts(array("post__not_in" =>get_option("sticky_posts")));

(from the codex)

Looks like that will only work on 3.0 or greater, though: http://wordpress.org/support/topic/excluding-sticky-posts-using-query_posts

Edit: in response to your comment below, try this (I'm not sure this will work, but hopefully it will get you started):

$the_query = new WP_Query($args);

    while ($the_query->have_posts()) : $the_query->the_post();

        $do_not_duplicate = $post->ID; ?>
share|improve this answer
thanks for the response. since I'm not using query_posts() in my example, how would I integrate your answer in what I have to work with? – Scott B Aug 27 '10 at 14:29
Scott, see above, I added some more. – tnorthcutt Aug 27 '10 at 17:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.