public function QueryInterface::condition

Add a condition to the query or a condition group.


  $entity_ids = Drupal::entityQuery($entity_type)
    ->condition('greetings', 'merhaba', '=', 'tr');
    ->condition('greetings.value', 'siema', '=', 'pl');
    ->execute();
  $entity_ids = $query->execute();

Parameters

$field: Name of the field being queried. Some examples:

  • nid
  • tags.value
  • tags this is the same as tags.value as .value is the default.

For example, to find all entities containing both the Turkish 'merhaba' and the Polish 'siema' within a 'greetings' text field:

$value: The value for $field. In most cases, this is a scalar. For more complex options, it is an array. The meaning of each element in the array is dependent on $operator.

$operator: Possible values:

  • '=', '<>', '>', '>=', '<', '<=', 'STARTS_WITH', 'CONTAINS', 'ENDS_WITH': These operators expect $value to be a literal of the same type as the column.
  • 'IN', 'NOT IN': These operators expect $value to be an array of literals of the same type as the column.
  • 'BETWEEN': This operator expects $value to be an array of two literals of the same type as the column.

$langcode: Language code (optional).

Return value

\Drupal\Core\Entity\Query\QueryInterface

See also

Drupal\Core\Entity\Query\andConditionGroup

Drupal\Core\Entity\Query\orConditionGroup

File

drupal/core/lib/Drupal/Core/Entity/Query/QueryInterface.php, line 67
Contains \Drupal\Core\Entity\QueryInterface.

Class

QueryInterface
Interface for entity queries.

Namespace

Drupal\Core\Entity\Query

Code

public function condition($field, $value = NULL, $operator = NULL, $langcode = NULL);