You could use a Taxonomy Query, like so:
$args = array(
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'terms' => array(),
'operator' => 'IN'
),
array(
'taxonomy' => 'category',
'terms' => array(),
'operator' => 'NOT IN',
),
),
);
$query = new WP_Query( $args );
This will query posts that are in the first set of terms AND not in the second set.
Related Posts:
- ajax category filter
- How to filter by category in REST API, excluding posts also in other category term?
- Exclude Category filter from Portfolio section
- Filter sub-category from checkbox form
- List categories using WP_Query
- I need to get all categories from a WP_Query
- Exclude post ID from wp_query
- How to list some posts first in the loop based on post id
- How to query only for products with status “in stock” in WooCommerce? [closed]
- WP_Query – filter or directly?
- What is the most efficient way of querying posts based on visits and date for current day?
- get_posts with multiple categories
- How to order posts tag by tag?
- Overriding The Loop with filter or hook
- Custom query incorrectly returning everything [closed]
- WP Rest API v2 return posts with specific tag
- How to order category.php loop by ‘meta_value’?
- How to support multiple search terms query within one process?
- Sorting Posts by custom field
- How to get any tag ID
- WP Query with multiple categories – passing an array works?
- wp_query display posts from same category of the post
- WP_query category__in not working, only pulls from first category
- WP_Query order by date in meta_value
- How get posts from a subcategory of a category by name?
- get complex results set according to category structure
- Searching through different categories on different pages code is not working
- How to implement time filter to show random post 1 month for one category and 3 months for other categories
- What’s the point of the query_vars filter?
- How to select posts from one category but exclude posts in another category?
- Refine/Filter WP_Query Posts with jQuery or Ajax
- How to apply filter inside a single wp_query?
- Get Category Archive Template Name Dynamically
- WP_Query arguments to fetch custom post type posts which are in certain category?
- When to add_filter() to Custom Query
- How do I reset this wp_list_categories query?
- How can you get first post, last post and post count in a category?
- Order by custom table and multiplication
- How can I remove posts of a certain category from homepage after a specified time period?
- How to get count of posts assigned to given category?
- How to show subcategories using loop?
- How to use filter hook “the_posts” with a function that refers to $this?
- Remove a specific category ID from related post
- add_filter() depending on search term
- query_vars filter not working even though query string parameter is present
- How do I run through a WordPress loop called from a filter function?
- How can I filter by slug depending on language selection
- wp_query ‘s’, search filter with pagination is not working
- category query for pages not working
- Bypass “supress_filters” in WP Query
- Search Query for multiple categories using ‘OR’ but having certain categories be ‘AND’
- Check if loop has any categories?
- WP_Query with different postmeta filter for each categories
- Avoid repeated post on page 2 when excluding one on page 1
- Slow WP_Query with ‘OR’ on meta_query
- How to alter local query, not main query [duplicate]
- How to filter a query by date in a shortcode?
- Inserting HTML to close and open divs in WP_Query loops
- Finding WordPress Posts assigned to multiple categories
- Changing the default wp_search_stopwords
- Exclude current post from an array of posts?
- Combine results of multiple WP_Query to resemble single WP_Query
- Loop doesn’t exclude the specified category in home page
- Exclude recently updated post from custom WP_Query using multiple loops
- WordPress Custom Search Form Displaying Unexpected Results
- Is it possible to add an argument to a custom function added to a filter hook?
- wp_query is showing posts from other categories
- How to display a list of posts in same child category as current post
- How to exclude a category name from showing?
- Loop categories by recent post
- I need to exclude from a query a category and a few custom taxonomies
- meta_query weird behaviour, static int will work, but not user data
- Related posts by current posts child category
- Filter products on category AND tag
- How can I have sticky posts while ALSO showing posts from a specific category using one WP_Query?
- How to use the Term Object from a custom select field in a query
- Related categories order posts by category
- Display All Top Child Categories / Taxonomy
- Query post by Category and custom file (ACF)
- Display 3 levels of categories on page
- Filtering ‘Featured’ posts from a batch of category IDs
- get term objects and post objects in query
- How to set selected attribute on option after filter query?
- Issue generating custom filter for cpt admin columns
- Help displaying related categories
- how to avoid reloading/refresh the page when displaying the post of wp_list_categories
- Show full category tree for a year with all post titles?
- query.php – multiple is_category functions
- Custom query with post_class filter using current_post not working
- Create multiple sections for all categories and then queries all the posts for each of those categories
- Filter WP_Query output before it is accessed (pre_get_posts)?
- Loop the posts between two dates selected using jquery datepicker
- Related posts with WP_Query
- Edit WordPress loop, taxonomies, & filter
- query_vars category_name only display one catgory out of multiple categories
- Woocommerce set loop_shop_columns to be 3 in the main shop page loop only and 4 otherwise
- Filters do not work when there are multiple (one works)
- Advanced Search – Is this possible?
- How to get post taxonomy url and name in wp_query
- Excluding a category from frontpage but not from WP_Query