2

I am trying to get all users that meta value is empty

so i tried many variations and cant get the list of all user that birthday field is empty (not set).

        $user_query->query_vars['meta_key']     = 'birthday';
        $user_query->query_vars['meta_value']   = '';
        //or
        $user_query->query_vars['meta_value']   = Null;
        $user_query->query_vars['meta_compare'] = '='; 
  • First, as a general observation, take notice that you are altering all of the queries so make sure you are altering only the one(s) that you need. Second, do the posts actually have that birthday meta_key with an empty meta_value in the wp_postmeta table? Or you want to fetch only those IDs that don't have that meta_key / meta_value at all set in the wp_postmeta table? – webtoure Jul 5 '15 at 14:01
3

I think the use of meta_query is in order:

$user_query = new WP_User_Query( 
    array( 
        'meta_query'=> array( 
            array( 
                 'key'=> 'birthday', 
                 'compare' => 'NOT EXISTS' 
            ) 
        ) 
     ) 
);

Basically, this looks for all users where the meta key of birthday doesn't have a value ie doesn't exist. More info about meta queries in WP_User_Query can be found here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.