I don’t think you can express logic like this in query arguments and custom SQL will probably be nightmarish.
I would try to flip the logic. Declare category__in
to be list of all categories, but the ones you don’t want.
You can build such list by code, like:
'category__in' => get_categories( array( 'fields' => 'ids', 'exclude' => '7,22' ) ),
PS I am not sure about performance aspect of such query, depends on number of categories involved I guess. Test before using in production.
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
- Exclude posts from featuring
- 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
- 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)
- Adding additional data to WP_Post object
- Count how many posts in category
- Custom Single Post By Category
- Inject post (from specific category) between posts in Loop
- WP_Query: Why is sticky post not first item in loop?
- Convert custom fields to post categories
- Most viewed post for the last 2 days using WP_Query
- Adding Post Counts to Menu (Nav) Programmatically?
- This AJAX Code Doesn’t Work – Looking for elegant solution
- Show One Category on Post
- Do I use custom post type or something else?
- What Defines What Category A Post Picks (if in multiple)
- Hide Post comments when displayed via WP_Query
- Show all post titles
- Add Category name to Post Title (h1)
- Posts are not showing up on particular category
- Blogroll – Different layout for first post
- Automatic value for custom fields for posts
- Loop through all product posts?
- Category Template: Need to display different content on first page of archives
- Display post category in foreach loop with category link
- Extracting post categories
- How to verify wp user password by sql query in wp? [closed]
- Lost draft under all posts and drafts
- List authors with the last post title and order by last post date
- How to order posts by meta_value and title
- How to display two blog categories as separate sections on one page?
- Print out last 3 blogposts
- get posts from Custom Post Type & Category
- How to group only VISIBLE posts? [closed]
- Shortcode with ‘year’ parameter
- How to enable custom Shortcodes in Post Category Description? [duplicate]
- How to call posts under a specific category on static front page?
- Get all custom posts with a certain taxonomy
- Link to date_query results in WordPress
- Limiting post list by taxonomy
- inserting a category into post
- Getting posts from some categories plus some individual posts
- Change layout of post depending on category
- Different post views for different category views
- Allow / show post comments in category pages
- How to select a category automatically based on a word in WordPress post title?
- Display default matabox of posts(add category) wordpress
- How display related post only in Default category on single
- How to get tags when using publish_post
- Function is printing twice – any suggestions?
- How to add class to specific navbar item when post parent category is in specific category
- How do you change the permalink for posts for a single category?
- Posts are not displaying on their category and tag page
- how to create a category with wp_insert_post and post_category
- How to add a block to a category page?
- How to use two query result together in one loop
- Excluding category from post navigation in WordPress?
- Custom Post By Category
- filter posts based on menu_order
- Post Category link is same with Page link
- Show custom post category for single post
- Get a list of categories that are related to posts
- Querying posts from current category, using a variable as array argument
- Wp_query loop is not working as it should
- Show all posts from the tags without having to set all of them
- Precedence of page permalinks over woocommerce product category links?
- Is there a global page/post/product/anything ID?
- wp query custom orderby not custom field
- Add category selection to function request
- Show Post number of specific Category
- How to display only one post on first category page and rest on next pages?
- wp_query posts sorting doesn’t work
- Viewing category won’t show up Custom post type posts
- custom sort posts in archive/taxanomy page
- Trying to create shortcode listing custom posts, but formating not being included
- Listing category and its posts one by one
- Print out one of 2 post category [closed]
- How to get if category has posts?
- Show some texts in posts belonging to Specific category