How do I get all posts that has a taxonomy term and a specific name/slug?
I have tried with the following arguments but without getting the wanted result. What am I missing, how can I combine the slug and term in the same query?
array(
'name' => '<name of post>',
'tax_query' => array(
array(
'taxonomy' => '<taxonomy>',
'field' => 'slug',
'terms' => <slug>,
'operator' => 'IN'
)
),
)
The SQL:
SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.post_name = '<slug-name>' AND wp_posts.post_type = '<post type>' AND ((wp_posts.post_status = 'publish')) ORDER BY wp_posts.post_date DESC
If I remove the "name" field the taxonomy part of the SQL looks right.
array(
'tax_query' => array(
array(
'taxonomy' => '<taxonomy>',
'field' => 'slug',
'terms' => <slug>,
'operator' => 'IN'
)
),
)
The SQL:
SELECT wp_posts.* FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND (
wp_term_relationships.term_taxonomy_id IN (2)
) AND wp_posts.post_type = '<post type>' AND ((wp_posts.post_status = 'publish')) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 5"