Last Updated: February 25, 2016
·
351
· branttedeschi

Excluding a Wordpress category throughout the site except when viewing the specific category

function exclude_category($query) { 
// 666 is the category
if ( !is_category(666)) { 
$query->set('cat', '-666');
}
return $query;
}
add_filter('pre_get_posts', 'exclude_category');

This will ignore the 666 category throughout the entire site. However, as implied by the is_category, the post will show up if you are specifically accessing that category via the blog or RSS feed.