David_George David_George - 2 months ago 7
PHP Question

Get_users who do not have meta_value

I am trying to search database with the get_users query and return users who's meta_value is everything except whats specified:

$unclaimed_users = get_users(array(

'meta_key' => 'has_won',

'meta_value' !=> '0'
));


For instance the users I need would have a meta value of anything apart from 0.

Any help would be hugely appreciated.

Thanks

David

Answer

It seems that your code is incorrect, try the following:

$unclaimed_users = get_users(array(
    'meta_key' => 'has_won',
    'meta_compare'  =>  '!=',
    'meta_value' => '0'
));
Comments