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?
Share Improve this question edited Feb 8, 2019 at 23:57 fuxia♦ 107k39 gold badges255 silver badges461 bronze badges asked Jan 12, 2014 at 0:32 Tpn KnvlTpn Knvl 32 bronze badges 2 |1 Answer
Reset to default 1You 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