Excluding Sticky Posts from The Loop and from WP_Query() in WordPress?

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:

http://example.com/test.php

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:

<?php
header('Content-Type:text/plain');
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();
  the_title(); 
endwhile;