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”
- When to use WP_query(), query_posts() and pre_get_posts
- order by numeric value for meta value
- Wp get all the sub pages of the parent using wp query
- Return only Count from a wp_query request?
- How to query for most viewed posts and show top 5
- How to use the_posts_navigation for wp_query and get_posts?
- meta_query: using BETWEEN with floats and/or casting to DECIMAL
- WP_Comment_Query pagination, delving into the unknown
- Usage of the new “posts_clauses” filter in WordPress 3.1?
- Get posts from Network (Multisite)
- How to order by post_status?
- Using get_posts vs. WP_Query
- Delete all posts from WordPress except latest X posts
- Make a WP Query search match exactly the search term
- WP_Query: query posts by ids from array?
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- Sanitation needed for WP_Query or get_posts calls?
- Differences Between WP_Query() and get_posts() for Querying Posts?
- Sort posts by category name and title
- How to uniquely identify queries?
- What is the most efficient way of querying posts based on visits and date for current day?
- Get Recent Posts by Date in Multisite
- Custom WP_Query order by post_meta and (author) user_meta
- get_posts with multiple categories
- Query WooCommerce orders where meta data does not exist
- get_template_part in for loop
- Use of caller_ get_ posts
- WP_Query for WooCommerce Products
- pre_get_posts with get_posts
- How-to exclude terms from the main query the most performant way?
- Is it possible to select against a post’s parent’s fields with WP_Query?
- How to know if get_posts() failed?
- Query all posts where meta value is empty
- author.php with ACF and CPTs
- Query Custom Meta Value with Increment
- When should you use wp_reset_postdata vs wp_reset_query?
- Identify which loop you are hooking into; primary or secondary?
- Get_post() with meta_key when compare is a date
- Perform query with meta_value date
- WP_Query ordered by custom field that is a date string?
- get_posts not finding argument: post_name
- Meta Query with date and time on the same Day before given time
- How to make an activities stream mixing posts and comments?
- Duplicate Queries
- Get posts with condition on comment meta value
- How to query for a week using key => value WP_Query argument notation?
- Finding all results from database within 500 miles of the given latitude and longitude [closed]
- Show only oldest post by author
- Order posts by tags count?
- SQL query equivalent to WP User Query
- Function to check if author has posted within the last x days
- Add and in the header while looping over custom query in page template
- How to get the posts published in last two days using WP_Query?
- Highlighting Sub topic in a post?
- Use post__in and post__not_in together?
- Which custom query am I in and how can I access its properties & methods?
- How to count post type that has a particular term?
- What should I use, get_posts or wp_query for less CPU load?
- Different Results with query(‘s=computer’) vs get_posts(‘s=computer’)?
- How to get post from all Blog Multisite to the Main Site?
- Finding the next 5 posts
- how to retrieve specific product attribute value in an sql query?
- WP Query post meta value
- Get all posts without tags
- Dynamically Override Fancy Title – Part II
- Transient pagination not working properly
- Foreach-generated custom tax queries, each with an ajax “Load more” button
- get_posts() seemingly ignoring post_type
- How to find out what “Blog pages show at most” is set to [duplicate]
- view queries made?
- Count posts returned by get_posts in external PHP script
- meta_query on a date range using an array of values
- WP_Query Performance Issues with meta_query
- Trying to check and see if a post has a featured image outside of the main loop
- WordPress custom archive page
- How to speed up wp_query, took more 5s to run against 100k posts
- How to detect custom query inside `posts_where` hook?
- Pass the same object to multiple widgets in a template with one query
- Is temporarily overwriting $wp_query a bad idea?
- Get the post permalink within the loop but without additional DB query
- Query Set Order By Author
- List the 5 most recent child pages
- Splitting the main query in multiple loops with query_posts and/or pre_get_posts?
- Retrieve or Query Pages by ID
- SELECT * FROM $wpdb->posts WHERE ID > 160
- How do you query wordpress posts using a math formula between multiple meta field values?
- Custom Post order for homepage