WordPress get_users(); returning wrong users

I have this call:

get_users('meta_key=main_feature&value=yes');

but the query is also returning users with the meta key ‘featured’ set to yes as well. I have a plugin that allows me to check all the user meta and have confirmed that the meta key for users that shouldn’t be showing up is empty.

Read More

Is there something I’m doing wrong here?

Related posts

2 comments

  1. As the WordPress codex says your arguments for the get_users function should be an array.

    So your query should look somethin like this:

    $args = (
        'meta_key' => 'main_feature',
        'value' => 'yes'
    );
    $users = get_users($args);
    
  2. Try to do something like below :

    $args = array(
        'meta_key'     => 'main_feature',
        'meta_value'   => 'yes',
        'meta_compare'  => 'EXISTS'
    ); 
    $u = get_users($args);
    

Comments are closed.