Last Updated: February 25, 2016
·
485
· 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.

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Related Tags
#php
#wordpress
Did you know?

WordPress sites collect scripts from themes, plugins, and tag managers. A compromised plugin update can add a skimmer to every page without a change in your own templates.

Security insights from Cside