We have a lot of blog post categories, and posts belonging to all but one category should show on the blog page. The other category should show on the Case Studies
page.
The solutions I've found make a global exclusion using functions.php
, which would break the Case Studies
sort.
I'm comfortable working with PHP but not sure how I would go about excluding the category on just one page.
Edit: Here is an example of category exclusion that I think would globally exclude category with ID of 1
in functions.php:
function exclude_category($query) {
$query->set('cat','-1');
return $query;
}
add_filter('pre_get_posts','exclude_category');
Below is one that is specific to a feed
page. Does it know to exclude it on the feed
page because feed
is the slug of the page to exclude for?
function exclude_category($query) {
if ($query->is_feed) {
$query->set('cat','-1');
}
return $query;
}
add_filter('pre_get_posts','exclude_category');
category-case-studies.php
) or are you using the defaultcategory.php
orarchive.php
or falling back onindex.php
?pre_get_posts
.