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

I am having alot of trouble with this. I was using <?php query_posts( array( 'post__not_in' => get_option( 'sticky_posts' ), 'paged' => get_query_var( 'paged' ) ) ); ?> to exclude the posts from the main query on the my homepage because stickies are being used in the slider. I am making this theme for wordpress.org and I was told that was not recommended. I then tried adding this to my functions.php but to no avail:

 * Excluding sticky posts from home page. Sticky posts are in a slider.
 * @since 0.1
function essential_exclude_sticky( $query ) {

    /* Exclude if is home and is main query. */
    if ( is_home() && $query->is_main_query() )
        $query->set( 'ignore_sticky_posts', true );



Any idea on what I am doing wrong?

share|improve this question

query_posts isn't recommended because its breaks things.

You're really close, but just declaring the function itself will not work. You need to hook the function into something. In your case, this would be pre_get_posts.

Example (with "namespaced" function):

// this is key!
add_action('pre_get_posts', 'wpse74620_ignore_sticky');
// the function that does the work
function wpse74620_ignore_sticky($query)
    // sure we're were we want to be.
    if (is_home() && $query->is_main_query())
        $query->set('ignore_sticky_posts', true);
share|improve this answer
Works like a charm. Thank you for explaining it, I need to learn these things! ;p – Steven Dec 2 '12 at 3:51
@Steven Click the check mark to mark this answer as The Solution. – toscho Dec 2 '12 at 9:02

For me, using ignore_sticky_posts keeps sticky posts from showing at the top, but they still show in chronological order with the other posts.

I'm using post__not_in with get_option('sticky_posts') to exclude sticky posts from the main query.

 * Exclude sticky posts from home page.
function theme_name_ignore_sticky_posts($query){
  if (is_home() && $query->is_main_query())
    $query->set('post__not_in', get_option('sticky_posts'));
add_action('pre_get_posts', 'theme_name_ignore_sticky_posts');
share|improve this answer

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.