lisaleague
3/27/2015 - 5:10 PM

From https://tommcfarlin.com/pre_get_posts-in-wordpress/To that end, you’re likely only going to want to exclude it from certain places. So

function demo_exclude_category( $wp_query ) {

    if ( ! is_admin() && ! is_search() && ! is_archive() ) {

        // Add the category ID to an array of excluded categories. Add multiples like this - ( '5', 'ID' )
        $excluded = array( '-1' );

        // Note that this is a cleaner way to write: $wp_query->set('category__not_in', $excluded);
        set_query_var( 'category__not_in', $excluded );

    } // end if

}
add_action( 'pre_get_posts', 'demo_exclude_category' );