I have an age filter, where it checks two custom fields, min_age
and max_age
, max_age
is optional so it can be empty.
These don't seem to work together:
array(
'key' => 'max_age',
'value' => $max_age,
'type' => 'numeric',
'compare' => '<=',
),
array(
'key' => 'max_age',
'value' => '',
'compare' => '!=',
)
If I remove the top array (<= filter), it returns the correct results, only showing results with the correct min_age and results that have a max_age value. How can I make them work together because the != '' max_age
filter is needed, otherwise the max_age
<= filter doesn't work correctly because it ignores that filter if the max_age custom field is empty.
$query->set( 'meta_query', array(
'relation' => 'AND',
array(
'key' => 'min_age',
'value' => $min_age,
'type' => 'numeric',
'compare' => '>=',
),
array(
'key' => 'max_age',
'value' => $max_age,
'type' => 'numeric',
'compare' => '<=',
),
array(
'key' => 'max_age',
'value' => '',
'compare' => '!=',
)
));