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?
- Check if a post is in any child category of a parent category
- exclude category from get_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
- How do I get the category URL from get_the_category?
- Display all posts from specific categories on a page
- Exclude certain category from latest updates
- get_field not displaying my custom field value
- Default WP Gallery – show only galleries of a certain category
- Exclude categories from Loop, queries, widgets, post navigation
- Rearranging posts based on categories
- WP_Query not looking at child category
- Randomise results from a category page?
- Using categories & “stickyness” together
- Display all posts in category, with specific tag posts at top
- Does the ‘cat’ argument in query_posts fetch posts from subcategories as well as the given ID?
- 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
- Display list of Sub-Categories and the posts they contain, within one main Category
- Loop with Dynamic Categories
- Excluding a category from next and previous post links
- How can I create a loop to build slides based on multiple categories using Coda Slider
- Display only the latest post from multiple categories
- Exclude Category From Home Page, Display Posts on It’s Own Page?
- Remove child products from woocommerce category page [closed]
- Get a list of commas separated categories inside a loop
- Categories list loop – add separator every year
- How would you create a “weekly” archive?
- Show children of top level category only
- Exclude a category from the filed under list only on some templates
- Listing all posts from current category on page
- How can I make wp_list_categories output li with category-slug as class, for its children?
- Select category in custom query
- Showing current subcategory
- How do I get the total number of categories in a list of search results?
- Check if post belongs to any category
- Return category slug / title from category ID
- Dynamically excluding current page id
- How do I display the posts from a custom post type on a category.php page?
- How to group the loop posts in a particular by author?
- Display products for a category, sorted by post_excerpt
- “NOT ONLY IN” taxonomy query operator?
- Listing Parent, Child and GrandChild Categories and then the PostTitles on Page Template !
- Category archive page – loop through posts of certain tag (with pagination) – pre_get_posts
- If newest post of category is newest post in general, skip first post of category
- a-z list, categories and sub categories in loop
- Show only first children level of current category?
- How to exclude posts from a category when using this particular format
- Why would in_category only return one post in a specific category?
- Is it possible to select and edit the way the most recent post from a certain category is displayed on the page?
- Exclude category from Tag Template
- exclude post from displaying in loop if it is in a category, but not in many categories
- Displaying multiple loops based off of category
- How to loop only categories without posts (+ show category featured image with acf) [closed]
- Additional featured post on first page
- I need to create a search form that will display search results from specific category
- Five posts from a category in footer
- Show all posts for a specific category/author
- Redirect category to url with /category
- create a page which displays a list of categories title+ short description?
- Post count for category and tag
- Enter a variable in the ‘category_name’ parameter
- Exclude Posts From Specific Category from Next and Previous post links
- Second level subcategory
- how to define category loop last class in the third
- Checking for two categories in query_posts
- How to query post like normal search would do. within search.php page
- exclude categories from search results
- Exclude category from fucntion
- how to query posts and auto assign category if post title has keyword
- How do I call posts with a certain tag?
- Show a Category X’s custom post type on Category X archive page?
- Modify WordPress SQL Query to pull from within a category
- query order by category
- Class active for Archive link – looped out
- Taxonomy name repeating when showing 2 posts from each category
- Display the last post by each category?
- Get link which associated with a specific category and tag
- WordPress category widget only show categories with children
- Remove product category placeholder image (Woocomerce)
- Category shows only top level child categories
- WooCommerce – How to show specific category first-rest of products-specific category last
- Counter in loop in foreach