DRUPAL 8 field Query

28 May 2021

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')
echo count($uids);

If you want to get more user through user id

foreach($uids as $uid){
	$users = User::load($uid);
22 Apr 2020

Code to query for getting node according to field condition in DRUPAL 8

$query = \Drupal::entityQuery('node')
  ->condition('status', NODE_PUBLISHED)
  ->condition('type', 'custom_type');
$and = $query->andConditionGroup();
$and->condition('custom_taxonomy', 2);
$and = $query->andConditionGroup();
$and->condition('custom_taxonomy', 8);
$result = $query->execute();