I am trying to use WP_Queryto create a query with both an element meta_queryand an element tax_query. The kicker is that I do not want to find results in which both conditions are satisfied (and the AND clause). I want to find the conditions under which one or the other is fulfilled (OR clause).
So, I start with these arguments:
$args = array(
'meta_query' => array(
array(
'key' => 'some-meta',
'value' => 'some-value',
)
),
'tax_query' => array(
array(
'taxonomy' => 'some-taxonomy',
'field' => 'slug',
'terms' => array('some-term')
)
)
);
On run, WP_QueryI get this where clause (simplified here for clarity):
WHERE ( wp_term_relationships.term_taxonomy_id IN (336) )
AND (
(wp_postmeta.meta_key = 'some-meta'
AND CAST(wp_postmeta.meta_value AS CHAR) = 'some-value')
)
Is it possible to pass any argument to an object WP_Querythat will change this first AND to OR? I want it:
WHERE ( wp_term_relationships.term_taxonomy_id IN (336) )
OR (
(wp_postmeta.meta_key = 'some-meta'
AND CAST(wp_postmeta.meta_value AS CHAR) = 'some-value')
)
source
share