David_George David_George - 1 year ago 89
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.



Answer Source

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

$unclaimed_users = get_users(array(
    'meta_key' => 'has_won',
    'meta_compare'  =>  '!=',
    'meta_value' => '0'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download