You can achieve that using the tax_query
, see the example in the code below:
$args = array(
'posts_per_page' => 10,
'post_type' => 'product',
'post_status' => 'publish',
'tax_query' => array(
'taxonomy' => 'the_taxonomy_slug', //the slug of the taxonomy you want to get
'field' => 'term_id',
'terms' => $categories
)
);
See reference in the Codex
Related Posts:
- Custom query filter not working on woocommerce category page
- Very slow query
- Show recent products first but “sold out last” in query
- Does meta_query work within get_posts array?
- How to show more than 5 posts?
- How to optimize my query filtering out unwanted data?
- Remove posts from query for events whose start date has passed
- get_posts() loop returns the same the_title() for each post
- Query Strings and Woocommerce
- List all posts from past week grouped by sub-category
- Order posts by custom field DATE value
- How do I see the mysql query generated by get_posts( $args )?
- Create Indexes for Slow Queries
- get_posts showing only 5 posts. (nopaging and posts_per_page -1 not working)
- pre saved posts query from db options table
- Query Nickname rather than Display Name in custom Woocommerce plugin
- Re-sort get_posts query results
- Can I include get_posts in this array?
- How can I get posts by 2 meta keys, prioritising one of them?
- How i make a custom sql query for Woocommerce
- Sort order in get_posts [closed]
- WooCommerce Total # orders [closed]
- Differences between wpdb->get_results() and wpdb->query()
- Using WordPress public query variables
- When/why does ‘$query->get( ‘tax_query’ );’ return empty?
- wpdb get posts by taxonomy SQL
- How to List Events by Year and Month Using Advanced Custom Fields?
- Is there any difference between hooks posts_where with posts_join and posts_search performance wise?
- Get a user’s most recent post title
- $query->query_var[‘post_type’] not set for pages
- Different Main Navigation per category
- Show All Posts Insert Edit Link
- Get IDs of posts currently visible on archive
- Get posts by category with pure SQL query
- can’t get query to order posts by acf datepicker
- Custom query to get terms from post ids
- Help with wordpress custom query and advanced custom fields plugin
- WordPress query by category, sorted by custom field
- Mysql / WordPress killing my server with 80k users [closed]
- Query all posts and not repeat the same tag
- Display related products with custom output
- Deleting data from a custom table in WordPress
- How many queries are normal to execute on a WP site?
- Insert static element only once in query archive
- How to run a mysql query when admin updates user role?
- Error when using setup_postdata()
- pre_get_posts : ‘post__not_in’ doesn’t work with global variable
- Getting post data from private page
- How to execute a SQL-query which contains multiple queries using $wpdb->query?
- Missing posts in a query
- Alter a specific query on WordPress
- SQL query to select posts from multiple categories
- Protect sequence of pages with same password for each of two groups of users
- How is it possible to get top comment from all children?
- Select Query demand excesive resources [closed]
- Query to get number of posts last week
- Query if audio attachment AND/OR custom field
- I want to create a filter for the query string is this possible?
- Exclude categories from the_category();
- How can i show all categories using wp query?
- WooCommerce search products between price range using WP_Query
- All in One Calendar Plugin Custom Post Type Query [closed]
- Get Posts from Last 24 hours and Sort them via GD Star Rating
- Query returning same results even though the ID changes
- Why my query ‘REPLACE INTO…’ does not work?
- DELETE WooCommerce Order data from database
- Restrict query to last day with posts
- Custom query object with Simple-Fields custom date field
- How to read the value of a WordPress $query associative array (hash) key
- Query posts based on previous query
- Waypoints + infinite scroll with custom query
- Customizing the_tags output?
- Querying with WP query using meta key price
- How do I get all results from my query
- Taxonomy filter under Polylang
- How to create an overview of posts with the same tag?
- create a link to a random post within the current category
- Pagination not working on custom post types with rewrite slug
- JetEngine Query Builder – order by value from repeater
- Change pure SQL database query to WordPress post query?
- Filter orders by modify date
- How to add url parameter to every search query in SearchWp?
- Woocommerce Get Orders By Meta Value
- custom sorting media with multiple filters – error: not unique table/alias: wp_postmeta
- Heavy meta query causing SQL crash
- Sort by postmeta on when searching
- Pulling an ACF into a query
- Speed up search query that searches in post meta?
- WP search exclude last letter from string
- modifying main query to query for ranges e.g. from 1999 to 2016
- Querying users by meta value and getting a strange answer
- Wpdb empty result only if language is Russian
- Problem on wpdb queries, wp_insert_post, wp_insert_user etc. The query runs twice
- Sort loop with query in the link
- About WP’s save_post action
- $wpdb: how to use a query as a base for another query?
- Multilingual WordPress page – using URL to determine language?
- list or get meta_key where meta_value is ‘something’
- WP_Query with checkbox meta_query – WordPress [duplicate]
- What is the best way to cache pages and queries in WordPress?