I was able to get the result that I wanted by putting the following into the functions.php
file in my theme directory:
function exclude_category( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'cat', '-208' );
}
}
add_action( 'pre_get_posts', 'exclude_category' );
The result of using this code was that any posts tagged with category 208 do not appear in the main blog, but they do appear in category 208 as well as in any other categories they are tagged with.
To exclude multiple categories, edit the following line of the above as follows:
$query->set( 'cat', '-208,-9,-50' );
You can find full details here.
Thanks to Milo for his comment pointing me in the right direction.
Related Posts:
- 404 Error On Category and Tags Pages
- Block multiple categories from Blog
- If newest post of category is newest post in general, skip first post of category
- How to create button to direct to certain category
- WordPress Genesis not excluding category from blog
- Putting a Category of posts under a Page
- how to “not” display new posts with a specific category on the main page?
- Functions.php: Exclude Category from “Blog”
- How can I display tags as categories?
- Display content from a specific category using cat ID not working
- Display subcategories in dropdown
- Add code to header based on category for specific posts?
- Use blog as base for tags and categories
- Restrict CSS on one page
- Rebuilding a Site: How to Show Several Category Posts in Woo Framework Theme?
- excude a specidic category from showing in the “relative posts”
- Category post count is not correct
- How to create category filter on a blog like on the site below?
- Blog page with posts from specific categories
- Is it possible to set up blog categories without changing permalink structure
- Redirect Category pages to blog page with query string
- Read More showing only on first post
- List post categories that link to a page showing those posts
- Pages, Categories, and working with someone else’s code
- Multiple Categories under one URL, where ‘Front Page’ is used already
- Restricting certain blog posts by date?
- Get posts from sites in Multisite?
- How to add the category ID to admin page
- WordPress remove separator from last item in wp_list_categories
- Filter categories using tags
- Need help adding custom field to category
- Show Post from parent category (custom taxonomy) ONLY!
- How to display a list of categories
- Number of posts in page – set per category and exclude sidebar
- Create single.php for specific category by category id
- is_category in pre_get_posts results in php notices
- Looking to exclude blog posts from category Previous/Next buttons
- Use get_term_children to get the sub category of a parent category for the current post
- How to make all posts in a category “unsticky”?
- How do I get the total number of categories in a list of search results?
- How to stop wordpress from showing the selected category on top of others in the category selection?
- advanced custom field Show field in special categry page [closed]
- Creating archive pages for children categories
- Exclude Child Categories Using wp_list_categories
- How do I get a list of all categories that a given user has written blog posts for?
- Arrange posts by date in front page
- “Categories” on my front page [closed]
- Warning: sizeof (): Parameter must be an array or an object that implements Countable, On products pages
- How to loop only categories without posts (+ show category featured image with acf) [closed]
- Add “page-a” slug to category link if user visit category link from “page-a”
- create a page which displays a list of categories title+ short description?
- select parent category first then child
- Scheduling update post daily
- How to exclude children categories of parent category
- Assign category from custom field on post creation and update
- Sticky posts not working when a specific category is set
- I want to display the all the posts that are inside a certain subcategory
- Category template with pagination returns 404 on next pages
- Display custom taxonomy attached to the post on post single page
- How to display numbered pages in a category
- How can I add an “ALL CATEGORIES” entry in wp_dropdown_categories?
- Ive got a term (get_term_by) but now I want to filter it by a category it is in?
- Get and show all of the available categories
- how to remove the default title of Categories widget
- Using a rich text editor for category description?
- How to put page numbers with the next/previous on a post/category list?
- How to get posts by category at /%category%/ url?
- Echo text using is_tag
- Group search results by category
- Custom row actions on a specific category
- How Do I Delete WordPress Posts Older Than 400 Days, From A WordPress Category
- Category Page Template – Can’t get category ID
- Filter Category Loop Dynamically
- Shortcode to display all the post from a category in a page
- WP Category Meta plugin fix? [closed]
- WP SQL Categories Export and Import
- How to display WooCommerce category image in my category page banner as a background?
- Why are my newly added categories not showing up when creating a post?
- Order wp_dropdown_categories by ASC or DESC
- Get a list of categories, separated by / to display inside the for custom metatags
- Get_term_meta() always returns false
- Displaying only selected categories
- get_the_category vs wp_get_post_categories
- How to get get_categories()’s ‘hide_empty’ argument to work with global year var in the archive template?
- Getting a sub category based on a category name
- I have many different products on my website how can I get them to display under specific categories?
- Help with SQL query, how to add taxonomie terms with value stored in options?
- WordPress Shop and restricting products and categories for some users/groups
- Pass list of categories to JS
- WP url to get rss with full text of post
- Display Referring Category on single post?
- Paginating a list of all posts collected by category titles
- Display deepest post category, when post have multiple categories
- Paginate WordPress Category Pages
- Get a list of post titles and links from yootheme master theme
- Customize category query in widget
- Page permalink rewrite
- Broken category styling
- Woocommerce Force the category choice before creating new product? [duplicate]
- Custom EndPoint not working when strip child category in URL