I’ve a custom post type ‘post-type-x’ and three custom taxonomies attached with it ‘taxonomy-1’, ‘taxonomy-2’ and ‘taxonomy-3’.
I want to retrieve all the posts that have custom taxonomies ‘taxonomy-1’ and ‘taxonomy-2’.
What will be the arguments array that I’ll be passing in query_posts function?
$args = array ( ..?.. )
I think this question can cause a misunderstanding. You say:
but
do you want post that have both taxonomy-1 and taxonomy-2 and taxonomy-3 is irrilevant?
or
Do you want post that have both taxonomy-1 and taxonomy-2 but not taxonomy-3?
or
Do you want post that have taxonomy-1 or taxonomy-2 and taxonomy-3 is irrilevant?
Note that these type of queries will be poor performant, because
get_terms
run a db query, so using code above you will have several queries that slow down the page view.If in the file that contains this code you can access to some variables that contain an array of id (or slug) of the taxonomy terms you can use them and improve performance.
Alternative is create a custom db query using
$wpdb->get_results
with an appropriate SQL query.