The intention is to search for customers who do not have coupon X or do not have any coupon.
$query = array (
'post_type' => 'clients',
'meta_query'=> array(
'relation' => 'OR',
array(
'key' => 'cupom',
'value' => $idCupom,
'compare' => '!=',
), array(
'key' => 'cupom',
'compare' => 'NOT EXISTS',
'value' => '',
)),
'posts_per_page' => -1,
);
I am doing according to other answers I found on the web, but the query returns wrong when it finds a post that has a meta_value different from the one searched.