So far I have tried these three options and all 3 of them are not working.
Option 1
$options = array(
'meta_key' => 'first_name',
'meta_value' => '',
'meta_compare' => '=',
);
$users = get_users( $options );
Option 2
$options = array(
'meta_key' => 'first_name',
'meta_value' => null,
'meta_compare' => '=',
);
$users = get_users( $options );
Option 3
$options = array(
'meta_query' => array(
array(
'key' => 'first_name',
'compare' => 'NOT EXISTS',
),
)
);
$users = get_users( $options );
It looks like you’re searching for the first_name
meta keys with empty string meta values:
$options = array(
'meta_query' => array(
array(
'key' => 'first_name',
'value' => '',
'compare' => '=',
),
)
);
$users = get_users( $options );
that generates this kind of SQL query:
SELECT wp_users.*
FROM wp_users
INNER JOIN wp_usermeta ON ( wp_users.ID = wp_usermeta.user_id )
WHERE
1=1 AND ( ( wp_usermeta.meta_key = 'first_name' AND wp_usermeta.meta_value="" ) )
ORDER BY user_login ASC
Note that
$options = array(
'meta_key' => 'first_name',
'meta_value' => '',
'meta_compare' => '=',
);
$users = get_users( $options );
generates this kind of SQL query:
SELECT wp_users.*
FROM wp_users
INNER JOIN wp_usermeta ON ( wp_users.ID = wp_usermeta.user_id )
WHERE 1=1 AND ( wp_usermeta.meta_key = 'first_name' )
ORDER BY user_login ASC ;