I’ve been trying to use tax_query
and meta_query
together in a WP_Query
argument, but that doesn’t seem to be working for some reason.
My code is:
$args = array (
'meta_key' => 'ratings_average',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'eventstart',
'compare' => '>=',
'value' => $tonight,
),
array(
'key' => 'eventstart',
'compare' => '<',
'value' => $tomorow,
),
),
'tax_query' => array(
array(
'taxonomy' => 'Music',
'field' => 'slug',
'terms' => 'fri'
),
),
);
$my_query = new WP_Query( $args );
Does anyone know where I’m going wrong in the code. Any help would be appreciated.
After print_r($args)
, it gives me the following result:
Array (
[meta_key] => ratings_average
[orderby] => meta_value_num
[order] => DESC
[meta_query] => Array (
[relation] => AND
[0] => Array (
[key] => eventstart
[compare] => >=
[value] => 17/04/14 00:00
)
[1] => Array (
[key] => eventstart
[compare] => <
[value] => 18/04/14 00:00
)
)
[tax_query] => Array (
[0] => Array (
[taxonomy] => Music
[field] => slug
[terms] => fri
)
)
)
Here’s a working snippet I’m using for my scenario, tweak as needed to match your needs.
Try this code,