I am having an issue here. I want to get all the post that are related to the current post at the same time it will also have a common category term.
for example:
Post XYZ has categories car, Truck, and Bus.
So i want to get any posts that have car or truck or bus at the same time it will also have category "Toronto"
What would be the query?
I am having an issue here. I want to get all the post that are related to the current post at the same time it will also have a common category term.
for example:
Post XYZ has categories car, Truck, and Bus.
So i want to get any posts that have car or truck or bus at the same time it will also have category "Toronto"
What would be the query?
You need a query like this -
$args = array(
'post_type' => 'post',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => array( 'car', 'truck', 'bus' ),
'operator' => 'IN'
),
array(
'taxonomy' => 'category',
'field' => 'name',
'terms' => 'Toronto'
)
)
);
tax_query
for complex taxonomy queries. – Milo Commented Jan 12, 2014 at 0:34