Hi, I’m trying to query multiple custom fields in a meta_query like:
'meta_query' => array(
array(
'key' => 'field1',
'value' => '1',
),
array(
'key' => 'field2',
'value' => '0',
),
),
Which works fine, but because field2 is a new field and isn’t populated on most posts, the query doesn’t show any results so I have to query for NULL and FALSE . The only way to do this is to change the meta_query relationship to OR and query field2 twice, which also means I can’t query field1 effectively anymore:
'meta_query' => array(
'relation' => 'OR'
// array(
// 'key' => 'field1',
// 'value' => '1',
// ),
array(
'key' => 'field2',
'value' => '',
'compare' => 'NOT EXISTS',
),
array(
'key' => 'field2',
'value' => '0',
),
),
Is there a way around this? Should I be updating all my existing posts with the new value first before querying for them?