Scroll
Drupal 8 Load entity by field value
Drupal 8 Load entity by field value
Drupal 8 Load entity by field value
1 answer
votes: 1374
Answer
You can achieve by using EntityFieldQuery.
For D8 EntityFieldQuery has been rewritten.
Drupal 8:
$query = \Drupal::entityQuery('entity_test');
$default_langcode_group = $query->andConditionGroup()
->condition('user_id', $properties[$default_langcode]['user_id'], '=', $default_langcode)
->condition('name', $properties[$default_langcode]['name'], '=', $default_langcode);
$langcode_group = $query->andConditionGroup()
->condition('name', $properties[$langcode]['name'], '=', $langcode)
->condition("$this->field_name.value", $field_value, '=', $langcode);
$result = $query
->condition('langcode', $default_langcode)
->condition($default_langcode_group)
->condition($langcode_group)
->sort('name', 'ASC', $default_langcode)
->execute();
How do I fetch the values of an entity's field?
$query = \Drupal::entityQuery('node')
->condition('status', 1)
->condition('changed', REQUEST_TIME, '<')
->condition('title', 'cat', 'CONTAINS')
->condition('field_tags.entity.name', 'cats');
$nids = $query->execute();