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'] = '='; 

1 Answer
1

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

Leave a Reply

Your email address will not be published. Required fields are marked *