logo

Select Query to get users of empty fields

28
May

Select Query to get users of empty fields
By: Anonymous | Published On: Fri, 05/28/2021 - 23:30

Select those users which name (Custom field) is empty

In the following I have created a custom field (name) in user profile, field machine name as field_name

I want get user list where name field is blank

 

$uids = \Drupal::entityQuery('user')
    ->condition('field_name', NULL, 'IS NULL')
    ->execute();
echo count($uids);

If you want to get more user through user id

foreach($uids as $uid){
	$users = User::load($uid);
	$users->get('name')->value;
}

Need Help ?