WordPress Snippets at WPcustoms

Ignore sticky posts from the main query

We use the pre_get_posts filter to modify the main query and set it to ignore sticky posts. Keep in mind that they won’t show up anywhere. You manually need to run a custom query calling only sticky posts above the main loop if you want to show them at the top.


/**
 * Snippet Name: Ignore sticky posts from the main query
 * Snippet URL: http://www.wpcustoms.net/snippets/ignore-sticky-posts-main-query/
 */
 function wpc_ignore_sticky($query)
{
    if (is_home() && $query->is_main_query())
        $query->set('ignore_sticky_posts', true);
        $query->set('post__not_in', get_option('sticky_posts'));
}
add_action('pre_get_posts', 'wpc_ignore_sticky');