tax_query for same level of a post_type
There is a post type ‘payment_methods’, which has two taxonomies , ‘category’ and ‘restricted-country’
So i want to query for ‘payment_methods’ which has taxonomy ‘category’ = ‘Online_Banking’ and ‘restricted-country’=’USA’ , there is case that ‘restricted-country’ taxonomy is not selected for a payment_method…
$name='Online_Banking';
$country_name = 'USA';
$args_p = array(
'posts_per_page' => $number,
'post_type' => 'payment_methods',
'no_found_rows' => true,
'post_status' => 'publish',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'field' => 'name',
'terms' => $name,
'operator' => 'IN'
),
array(
'relation' => 'OR', //2nd try 'relation'=>'AND'
array(
'taxonomy' => 'restricted-country',
'field' => 'Name',
'terms' => array($country_name),
'operator' => 'NOT IN'
),
array(
'taxonomy' => 'restricted-country',
'field' => 'term_id',
'operator' => 'EXISTS'
)
)),
'meta_key' => 'rating',
'orderby' => 'meta_value_num',
'order' => 'DESC'
);
the return of the restricted-country is false for not selected taxonomy ” , and 1 for selected
By running that query i get all the ‘payment_methods’ for which ‘restricted-country’ taxonomy was selected, but many of the ‘payment-methods’ are violating the ‘restricted-country’.
2nd try I checked with second ‘relation’=>’AND’ , then no result was returned…
I cant catch what i am missing here?
Is it possible to query for ‘payment-methods’ for category ‘Online_Banking’ AND (‘restricted-country’ is not false(”) AND country_name is NOT_IN in the certain taxonomy???
Leave an answer