I think, you can try this type of code.
$args = array(
'post_type' => 'product',
'meta_key' => 'sorting_weight',
'orderby' => 'meta_value_num',
'posts_per_page' => - 1,
'order' => 'DESC',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => 81, // category 1
),
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'operator' => 'NOT IN',
'terms' => 82, // category 2
)
)
);
Related Posts:
- Display Featured Post by Categories and Avoid duplicated posts
- Search Query for multiple categories using ‘OR’ but having certain categories be ‘AND’
- How to echo woocommerce category name
- How to get posts by category and by choosing a taxonomy term?
- get_the_terms has strange result since version 6.0
- Use get_cat_ID to retreive multiple category IDs
- How to use the Term Object from a custom select field in a query
- Category Archive not working for pages
- Exclude or Include category ids in WP_Query
- WP query taxonomy input differs to output?
- Search custom taxonomy term by name
- How to query only for products with status “in stock” in WooCommerce? [closed]
- Combine two taxonomies in a hierarchical tree
- WP_Query to show post from a category OR custom field
- get_posts with multiple categories
- How to display post from current Taxonomy in archive page?
- Exclude posts that only have the ‘Uncategorized’ category [duplicate]
- ajax category filter
- Display posts the match taxonomy term linked from wp_list_categoies?
- Display recent posts from the same category as current post in sidebar
- Why is my WP_Query not working when tax_query terms are an array?
- How to filter by category in REST API, excluding posts also in other category term?
- Counting number of posts with Category B in Category A
- How to order category.php loop by ‘meta_value’?
- Use Transient API to cache queries for all posts in all categories?
- How can I display recent posts from a particular category in my header?
- Move posts to top of WP_Query if in certain Taxonomy?
- Sorting Posts by custom field
- Querying Multiple Custom Taxonomy Terms
- Filter and list posts of a custom taxonomy
- List all custom post type posts from a given category?
- WP Query with multiple categories – passing an array works?
- WP Query – Get WooCommerce Products with variation that is in stock
- wp_query display posts from same category of the post
- How to show only one post for each categories of taxonomy of custom post that contains a specific custom field
- 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?
- Filter WordPress posts by between parameter
- get complex results set according to category structure
- How to Modify Taxonomy Archive Page with Search Parameter?
- How to add terms to my tax_query based off of the current post
- Searching through different categories on different pages code is not working
- Filtering posts by custom field value not working
- How to query posts from specific authors and categories using WP_query?
- Show Post Count of a Category
- Get image of latest post from taxonomies/categories
- How To Remove/hide some specific categories from two different categories widget from sidebar
- Display link to taxonomy archive only if it has posts with certain custom field values
- How to select posts from one category but exclude posts in another category?
- Order taxonomy terms in alphabetical order
- Is it possible to dynamically get queried term AND taxonomy?
- WP Query for variable taxonomies
- How do I search inside specific taxonomies in WordPress
- Pass array of taxonomy terms to wp_query
- Get Category Archive Template Name Dynamically
- WP_Query arguments to fetch custom post type posts which are in certain category?
- How do I reset this wp_list_categories query?
- Formulate a url to show posts with both taxonomy terms
- How can you get first post, last post and post count in a category?
- How to get count of posts assigned to given category?
- Taxonomy search/filter with multiple taxonomies and multiple taxonomy terms
- How to show subcategories using loop?
- Order by slug in get_terms with multiple taxonomies
- Output an array of terms for a ‘tax_query’ => array()
- How to show CPTs in term archive
- Function get_queried_object() return NULL in custom taxonomy
- List of the years with posts presented
- Getting Taxonomy inside WP_Query Loop
- Remove a specific category ID from related post
- Complex Category selection as per user input
- Show all post for a given category
- Complex WP_Query (two post types and multiple operators)
- Five posts from a category in footer
- WP_Query Not Recognizing Taxonomy Parameter in Custom Search
- Return Taxonomy/Term Information with Posts (WP_Query/get_posts)
- How to get all unique categories for posts in loop?
- Remove category from query (show all posts in archive.php) pre_get_posts()
- is_tax() function not working as expected
- Advanced Taxonomy Queries WordPress
- Cluster WooCommerce products in each Category Archive by Tags assigned to products
- Category applied to pages, creates multiple breadcrumb entries after a search query (On the translated site)
- Get authors by term id or slug
- category query for pages not working
- WP_Query tax query part of slug
- Can we return all category (not post) with Custom Query Filter? [closed]
- Taxonomy Query Relation field not behaving correctly?
- WP Query Args – Title or Taxonomy Value
- How to Union two different conditions in one WP_Query
- Query posts intersecting tags and categories
- Slow queries on a huge database
- How do I exclude the lowest level terms in a taxonomy?
- Query posts from category A, and from either category B or C
- Combining categories (Query posts with multiple taxonomy terms)
- Check if loop has any categories?
- Filtering out child category posts from parent category archive not working
- Exclude Category filter from Portfolio section
- Post loop for all taxonomy terms
- wp_query args adding muitiple tax_querys
- Taxonomy and Date in same query?