I recommend you use the pre_get_posts
filter or ditch query_posts
and use WP Query
.
That way you can easily use category__not_in (array)
parameter and not mess any other loops up.
function exclude_category($query) {
// this requires term id instead of term name so change "20" to the "sport" id
// this assumes "sports" is in a category and not a custom taxonomy
$child_cats = (array) get_term_children('20', 'category');
//only effect main home page query
if ( $query->is_home() && $query->is_main_query() ) {
$query->set('category__not_in',array_merge(array('20'), $child_cats));
return $query;
}
}
add_filter('pre_get_posts', 'exclude_category');
ps. I did not test this but in theory it should work.
Related Posts:
- Get the children of the parent category
- Exclude the category from the WordPress loop
- List posts by category exclude current post
- How to exclude categories from recent posts, recent comments & category widgets?
- Display one latest post from multiple categories
- Exclude category from loop not working
- Order by category titles
- Pagination on category.php and tag.php not working
- Problem with different query loops (and “main loop”) on category template page!
- Have posts that belong to multiple categories, exclude some categories from homepage
- Assign a class to first element in category in loop
- Displaying Category in sidebar post widget but not in the loop on home
- How to have a category not show up in query post with page panigation?
- Get posts from sites in Multisite?
- How to check if I’m on the last page of posts?
- How To Modify The Loop in archives.php To Have 11 Posts Per Page and CSS Styling
- Should category.php and The Loop be used if the query needs to be customizable?
- How to make child categories recognize parent’s template displays
- get_field not displaying my custom field value
- Exclude categories from Loop, queries, widgets, post navigation
- Randomise results from a category page?
- Show div only if post is in specific category
- wp_list_categories exclude not working
- How to show a category post to a specific registered user
- How can I make wp_list_categories output li with category-slug as class, for its children?
- How do I get the total number of categories in a list of search results?
- Dynamically excluding current page id
- Display products for a category, sorted by post_excerpt
- “NOT ONLY IN” taxonomy query operator?
- a-z list, categories and sub categories in loop
- How to exclude posts from a category when using this particular format
- Exclude category from Tag Template
- exclude post from displaying in loop if it is in a category, but not in many categories
- How to loop only categories without posts (+ show category featured image with acf) [closed]
- Additional featured post on first page
- Show all posts for a specific category/author
- create a page which displays a list of categories title+ short description?
- Exclude Posts From Specific Category from Next and Previous post links
- Exclude category from fucntion
- how to query posts and auto assign category if post title has keyword
- Class active for Archive link – looped out
- Counter in loop in foreach
- Have parent category contain only one post?
- Inside a loop, how to change CSS class based on category name?
- Randomly load categories with latest post
- query_post order desc
- Limit get_categories to show each category once
- Is there a reason I cannot get the current category in a loop?
- Category archive is displaying all posts rather than the specific category
- new WP_Query all post in a category inside the loop
- category__not_in and id values from variable
- Give Children Unique ID’s
- How to display the parent category if only the child category has been chosen
- Category tags with comma’s
- Allow user to select categories that will display in post loop
- Posts from a category on homepage with category archieves page default css
- Remove any product that is featured from regular display loop [WooCommerce]
- Two Sections on Woocommerce Catergory Page [closed]
- Getting the Most Recent Posts from Multiple Categories
- wp_list_categories not excluing multiple ids
- Display subcategories in dropdown
- Display category title and three latest post inside the category
- More efficient way to list posts by category [duplicate]
- How to exclude posts from category posts count
- Exclude category from foreach loop
- Limit Loop to One Category
- wordpress taxonomy query posts
- Filter Category Loop Dynamically
- how can i hide category?
- Homepage custom recent news
- Editing Loop So It Targets Specific Tags?
- Conditional category query breaking?
- Problem: retrieving parent category’s first post
- Exclude the category in WordPress
- Sort posts alphabetically by category/custom taxonomy, insert divider between different types
- Category name for all posts getting assigned to a single random post
- Category post count is not correct
- Include last post date in get_categories loop
- How to get specific (grand parent) category of current post?
- Custom Loop with certain number of one category
- how tho change number of posts in loop from specific categories
- Template category.php with page (no posts)
- Exclude a category and post_type from wp_query
- error in specific category loop
- loop in single.php of the same category
- Please tell how to stop the category from showing up on posts
- Hide a category/posts from the homepage in wp
- Exclude category and post from loop in custom category.php
- Trying to display all posts in a category
- Display Taxonomies in loop with template args
- How to get multiple loop in category.php, my scripts becomes madness
- Custom Category Page Not Working [duplicate]
- Paginate WordPress Category Pages
- single.php fires more than once after clicking on any post to view with different post id each time
- Custom loop by url
- how to display page title only for child category pages
- Customize category query in widget
- IF have_posts contains posts from a certain category
- Excluding cateory not working on my site. how to solve this? [closed]
- How to define category ID in an array?