You could do something like this:
function exclude_category($query) {
if ( $query->is_home() ) {
$query->set('cat', '-46');
}
return $query;
}
add_filter('pre_get_posts', 'exclude_category');
where 46 is the ID of the category you want to exclude.
Hi OakwoodGates,
I will give it a try and see if that works.
Thanks.
Hi OakwoodGates,
I cannot see any id for the categories. Where can I find out what id the specific category has?
If you are in the wp-admin->Posts->Categories, and click on the category, then take a look at the url in the browser. Somewhere in that url, you should see something like ID=46 (or whatever).
Does that make sense?
That does make sense. I am going to check it out.
I use this code to exclude my categories from various places, similar to what oakwoodgates posted:
function remove_my_categories( $wp_query ) {
// 61 = Daily Tweets, 74 = Testing
$remove_cat = '-61,-74';
// remove from archives (except category archives), feeds, search, and home page, but not admin areas
if( (is_home() || is_feed() || is_search() || ( is_archive() && !is_category() )) && !is_admin()) {
set_query_var('cat', $remove_cat);
//which is merely the more elegant way to write:
//$wp_query->set('cat', '-' . $remove_cat);
}
}
add_action('pre_get_posts', 'remove_my_categories' );
Whatever works. 🙂
Hi MarkRH,
Thanks for your code.
I will test your code as well.