Excluding specific categories from WP_Query
This is in the codex. You can exlclude specific categories from WP_Query. Where array(2, 6) are IDs for categories to be excluded in this example.
$query = new WP_Query( array( 'category__not_in' => array( 2, 6 ) ) );
See the codex:
https://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters
NOTE: If you are trying to exclude category by the name of category
First you would do this to find the category ID by providing category name.
$category_id = get_cat_ID( 'My Category' );
then add the returned $category_id
in your WP Query arguments it would look like this:
$query = new WP_Query( array( 'category__not_in' => array( $category_id ) ) );
Related Posts:
- Exclude posts that only have the ‘Uncategorized’ category [duplicate]
- Show related posts by category but ignore one category
- prevent showing posts of an specific category in admin posts section
- How can I remove posts of a certain category from homepage after a specified time period?
- List posts in a given category
- Get user categories with most posts in it
- Loop doesn’t exclude the specified category in home page
- Display posts of specific category term
- Migrate posts from category and sub-category via SQL
- WP_Query of Category Not Showing First Post
- Sidebar limiting to 10 posts?
- Query prints posts without specific categories
- show image gallery in archives or category page
- Page with Category Returning 1
- Get 5 most recent categories
- How can I display a specific number of post in a category via a url
- Order posts by separate menu order for different sub-categories
- Retrieve latest post by multiple categories with ID
- Make assigning post to a specific category equivalent to assigning it to all categories
- How to Include a common category in a custom Category Search
- WP_Query: Fetch posts that are in (category1 and not in category2), OR posts that are not in cagegory1
- Exclude sub sub categories from displaying in the archive page
- List posts related to category on a div [closed]
- Show Title/Date/Excerpt of first post & only Title for rest in Query [duplicate]
- Filters do not work when there are multiple (one works)
- Querying post from a multisite network
- How to know if get_posts() failed?
- Post content being duplicated by the_content();
- How to add padding between posts
- Working Bootstrap Carousel Conversion to WP – Technical Questions
- Add custom field to category of custom post type
- Add few specific post ids to wp_query
- Can I hide a specific post from latest posts page?
- How to show post(excerpt) from specific category on wp page?
- WordPress – Admin Manage Posts – Multiple Filters by Parent Category
- Custom Theme Want To Remove One Category From All Displays
- WP_Query posts_per_page ignored
- Different template for posts of all subcategories of category
- wp_query ‘s’ parameter does not work with custom post type
- How to limit displayed posts on wordpress
- Select a random post from a specific category?
- Accessing post->ID outside of the loop for listing child pages
- How to filter posts that belong to a specific category only if that is the only category
- Category List (Archive) Page Template By Category
- Reset Popular post query?
- Query Posts multiple conditions
- Future post ID not showing
- Show custom post type filtered by category
- post categories
- Search by post title and content in wp_query without order
- How can i limit the number of posts created per category?
- How safe is renovating $wp_query when doing WP_Query pagination in Page Template
- How can I hide tags on a child-category page, if that tag has not been used?
- How do I stop the loop from repeating in my category template?
- how to get post order by post id wp_query?
- Is it possible to add/tick a category to a post when it is created?
- How to display all posts divided/ordered by post date? [closed]
- Is it possible to use WP_Query to only pull posts with attachments?
- store posts_id of category into a varable?
- Can’t understand why sometimes a [caption] field appears
- Latest posts by category — how to exclude current post?
- How to get post with associated categories and tags names instead of ids with rest api?
- Display a mixed list of posts and media
- Why in my query is display two title?
- wp_query with ajax
- How to convert query sql to shortcode in wordpress?
- Use posts_where to exclude posts ids from wp_query
- How to list post as buch of category, and all of them
- How can I add a page that shows posts from a single category?
- Post in bulk based on category template
- Remove subcategory slug from url
- Can I show category name in url for only one of my categories?
- Automatic duplicate/copy of post to a related page in WordPress
- Change Old WordPress Post Date Year
- Yoast breadcrumb URL shows category instead of the page
- Display/Filter post using if else statement
- Search results for ACF data
- Current post categories and subcatecories outside of the loop
- Foreach issue in get_posts function
- Numbered Pagination Showing The Same Posts After Altering WP_Query
- Custom post styling per category?
- Manipulate query to show specific post
- post categories – how to show only categories with a specific parent id
- Creating a “category” of featured posts
- How do I make it so that new posts within a certain category go into a certain page?
- WordPress text field in array problem
- My custom query is displaying random posts in random order
- List Authors For Current Category
- Get query result according to merged array
- Assign specific ads to specific categories/posts
- Multiple loops on a Search result page?
- Use radio buttons & checkboxes for post categories
- Add default content to post (for specific category)
- List posts that are in the same category as the current post title
- Multiple blog “feeds” in a single blog each with distinctly styled post pages
- How to get pagination working with “Pending” Posts
- How do I show the post title if an advanced custom field hasn’t been used?
- Post’s arent displaying
- Show with echo if a post has two or more categories
- How add class the_content();?