function EntityFieldQuery::entityCondition

Adds a condition on entity-generic metadata.

If the overall query contains only entity conditions or ordering, or if there are property conditions, then specifying the entity type is mandatory. If there are field conditions or ordering but no property conditions or ordering, then specifying an entity type is optional. While the field storage engine might support field conditions on more than one entity type, there is no way to query across multiple entity base tables by default. To specify the entity type, pass in 'entity_type' for $name, the type as a string for $value, and no $operator (it's disregarded).

'bundle', 'revision_id' and 'entity_id' have no such restrictions.

Note: The "comment" entity type does not support bundle conditions.

Parameters

$name: 'entity_type', 'bundle', 'revision_id' or 'entity_id'.

$value: The value for $name. 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': 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.

The operator can be omitted, and will default to 'IN' if the value is an array, or to '=' otherwise.

Return value

EntityFieldQuery The called object.

File

includes/entity.inc, line 672

Class

EntityFieldQuery
Retrieves entities matching a given set of conditions.

Code

public function entityCondition($name, $value, $operator = NULL) {
    // The '!=' operator is deprecated in favour of the '<>' operator since the
    // latter is ANSI SQL compatible.
    if ($operator == '!=') {
        $operator = '<>';
    }
    $this->entityConditions[$name] = array(
        'value' => $value,
        'operator' => $operator,
    );
    return $this;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.