Exclude sticky post from main query?

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

<?php
// 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);
}

Leave a Comment