I am using following meta_query to search blog post according to following search criteria,
search logic :
- if expire date set, check the expiry of the post, otherwise just include it
- if country(
$_country
) in the filters, search for that particular country with above expire date rule. otherwise just apply the expire date rule.
meta_query:
$expire_meta_1 = array(
'key' => '_simple_fields_fieldGroupID_3_fieldID_7_numInSet_0',
'value' => '',
'compare' => 'NOT EXISTS'
);
$expire_meta_2 = array(
'key' => '_simple_fields_fieldGroupID_3_fieldID_7_numInSet_0',
'value' => date("Y-m-d"),
'compare' => '>=',
'type' => 'DATE'
);
if($_country!=''){
$country_meta = array(
'key' => '_simple_fields_fieldGroupID_3_fieldID_8_numInSet_0',
'value' => $_country,
'compare' => '='
);
$args['meta_query'] = array( 'relation' => 'AND', array( 'relation' => 'OR', $expire_meta_1, $expire_meta_2), $country_meta);
} else{
$args['meta_query'] = array( 'relation' => 'OR', $expire_meta_1, $expire_meta_2);
}
the issue is, if it is country search, post should set the expire date. but I need to select the posts also not set the expire date.(if set check the expiry, that is anyway working).
But if I am not searching for specific country, the expire date rule(rule 1) is working properly.
Anybody have any idea what is my mistake. Any help would be appreciate.
I hope question is clear, otherwise I can provide more details, please let me know.
Thanks in advance.