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
- How to query only for products with status “in stock” in WooCommerce? [closed]
- get_posts with multiple categories
- Exclude posts that only have the ‘Uncategorized’ category [duplicate]
- ajax category filter
- Display posts the match taxonomy term linked from wp_list_categoies?
- Why is my WP_Query not working when tax_query terms are an array?
- How to order category.php loop by ‘meta_value’?
- 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
- 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
- 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 query posts from specific authors and categories using WP_query?
- Show Post Count of a Category
- How to select posts from one category but exclude posts in another category?
- Order taxonomy terms in alphabetical order
- How do I search inside specific taxonomies in WordPress
- 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?
- How can you get first post, last post and post count in a category?
- How to get count of posts assigned to given category?
- How to show subcategories using loop?
- How to show CPTs in term archive
- Remove a specific category ID from related post
- category query for pages not working
- WP Query Args – Title or Taxonomy Value
- Slow queries on a huge database
- How do I exclude the lowest level terms in a taxonomy?
- Check if loop has any categories?
- wp_query args adding muitiple tax_querys
- Automatically Query Parent Taxonomy
- Inserting HTML to close and open divs in WP_Query loops
- How Can I Change The Tax Query For The Main Loop For Taxonomy Archives?
- Custom taxonomy.php not working
- WP_Query for a taxonomy with different taxonomy types
- Finding WordPress Posts assigned to multiple categories
- How to Order a list of taxonomies? orderby?
- How to add custom meta to ‘pre_get_terms’?
- wp_query is showing posts from other categories
- WP Job Manager plugin – Listing only the twelve job categories on frontpage order by jobs they have
- WP_Query Taxonomy categories filtering
- How to load a script code only in posts?
- Get posts in taxonomy randomly
- Loop posts based on permalink term
- 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
- Get the child category ID of current category
- Related Posts Excluding Certain Categories
- Custom taxonomy in WP_Query not working
- How to make a post with certain taxonomy term display first before other post with only one query?
- Post incorrectly excluded when using “category__in”?
- Related posts by current posts child category
- Filter products on category AND tag
- How can I order a post query’s results based on the number of matching taxonomy terms?
- Only show tag with the same id as the post
- query hook parse_tax_query function takes no effect
- How can I have sticky posts while ALSO showing posts from a specific category using one WP_Query?
- Categories In English version showing not canonical URL, instead shows query search result
- wp_query with meta_query and tax_query
- What code to use in an array to call the current sub-category?
- Pagination for Category does not work
- Query post by Category and custom file (ACF)
- WP_Query showing all posts, except from category X, unless it’s also in Y
- Single query for multiple categories
- Page with Category Returning 1
- Taxonomy archive, categorised by other taxonomy, not hiding empty taxonomies
- Display 3 levels of categories on page
- Filtering ‘Featured’ posts from a batch of category IDs
- taxquery taxonomy get terms
- pages shortcode filtering by category
- How to show terms from another taxonomy
- Help displaying related categories
- how to avoid reloading/refresh the page when displaying the post of wp_list_categories
- How can I get all the posts that are related with a specific taxonomy term?
- Show full category tree for a year with all post titles?
- Search format not matching taxonomy query
- Display post list within category list sorted by name [duplicate]
- Create multiple sections for all categories and then queries all the posts for each of those categories
- Related posts with WP_Query
- Main loop querying current template’s info only in custom category archive pages, not my posts
- query_vars category_name only display one catgory out of multiple categories
- Custom query for certain post type OR another post type with a certain category
- Pagination only showed when no category is set in wp_query