Both get_posts()
and wp_query()
should be able to do this by passing the tax_query
array into them.
Example:
$query = array(
'post_type' => 'portfolio',
'post_status' => 'publish',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'clients',
'field' => 'slug',
'terms' => array( 'acme' )
)
),
'orderby' => 'menu_order',
'order' => 'ASC'
);
$posts = get_posts( $query );
Related Posts:
- When should you use WP_Query vs query_posts() vs get_posts()?
- WP_Query vs get_posts
- Get posts by meta data OR title
- Can not switch the queried post in pre_get_posts hook
- WP_query category__in not working, only pulls from first category
- Creating a custom search for a specific post type
- Weird orderby => post__in issue
- Check return value of get_posts
- Prioritising and Ordering Posts By Category Name Using A Custom Loop
- How to get meta key list efficiently?
- Ordering Posts by parent category, name ascending
- When should you use WP_Query vs query_posts() vs get_posts()?
- A Depth Like Parameter For “get_posts”
- Get posts from Network (Multisite)
- Sanitation needed for WP_Query or get_posts calls?
- What is the most efficient way of querying posts based on visits and date for current day?
- Use of caller_ get_ posts
- When should you use wp_reset_postdata vs wp_reset_query?
- Meta Query with date and time on the same Day before given time
- Get posts with condition on comment meta value
- Order posts by tags count?
- Add and in the header while looping over custom query in page template
- Which custom query am I in and how can I access its properties & methods?
- What should I use, get_posts or wp_query for less CPU load?
- How to get post from all Blog Multisite to the Main Site?
- How to speed up wp_query, took more 5s to run against 100k posts
- How do you query wordpress posts using a math formula between multiple meta field values?
- Get image of latest post from taxonomies/categories
- How To Get Some Data From WordPress Database Using WordPress $wpdb Query?
- Undefined WP_Query::has_posts()?
- WP_Query, tax_query and term_meta: How to?
- Is it possible to dynamically get queried term AND taxonomy?
- Pull post meta with post_query?
- get_posts – get all posts by array of author
- How to access a query twice in different template files?
- Minimize database queries to user tables?
- Query all published post AND attachment with specific mime type
- Return only post(s) which have post_excerpt
- Get all products which have both product category
- unable to retrive parent page information
- Page displays content from different query?
- How to display user order by role
- WP Query related posts by tags
- Order by summing multiple values
- Order by empty custom field
- Check if loop has any categories?
- No results found from a $wpdb->get_results() query when trying to join more than one meta key query
- WP_Query post_parent parameter always returns children of current page
- How to count posts with specific arguments
- Query only the posts with a post format of “audio”
- pre_get_posts – Trying to get property of non-object warning
- WordPress query posts with multiple post_meta data
- get_posts output always same post
- complex get_posts() query to select child pages
- Yoast primary category query modification
- Update query for wp_posts and wp_postmeta
- Related Posts function not working
- Function using get_posts() with tax_query not working when called from functions.php
- Include one page/post into query which is already returning posts
- Search for pages with permalink
- Insert images into wordpress post with a query
- Why doesn’t my WP Meta Query return any results?
- WP_Query meta compare must include ALL array values
- How to query for a page, get data, then query for child pages of that page
- Disable (or limit) queries when certain content (or data) is not needed (or showed)
- get_posts query is taking about 40 seconds to execute
- pre_user_query vs pre_get_posts
- Adding nofollow to all the post links in get_posts with pre_get_posts or WP_Query
- Meta query orderby meta_value_num sorting by role first
- Why pagination is not working with tax_query param?
- WP_Query & Duplicate entries
- Add to search posts query array with post IDS which will appear first
- How to show terms from another taxonomy
- My entry results are not consistently alphabetized
- Ignoring ‘a’ when sorting posts
- I cannot get tax_query in get_posts() to work with custom taxonomy
- Custom query for tag and custom tag from 2 post type
- wpdb get_results() returns only 2 rows
- Query posts in current category but not attachment format
- WP_Query secondary query failing
- Search Functionality broken by the wp 4.2 update
- Issue attempting a wp_query_posts with tags
- wp_query – Modify $query to include duplicate content
- Optimising specific Query with ACF meta objects
- How to get several fields from wp_query?
- add_query_vars does not work
- Pagination not working with WP_Query (creates links but no page)
- Why WP_Query in functions.php is not working when get_posts works?
- Query custom post type by date field only working when two posts match the query
- Divide WP_Query posts by date & post type
- Query Posts by date range with fixed beginning and end
- query by meta value then date and not empty meta value
- New WordPress WP Query using posts from certain categories
- Query specific number of posts for each post type in specific order
- get_posts shows current post, not defined posts with args
- WordPress extremely slow when using get_posts with multiple meta_query relations
- Use meta query only 3 or more results?
- Search results stuck on page 1
- Use value from meta key array for use in WP_Query
- Sort by multiple columns using get_posts