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.
Written by Brant Tedeschi
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#