7.x entity.inc EntityFieldQuery::propertyCondition($column, $value, $operator = NULL)

Adds a condition on an entity-specific property.

An $entity_type must be specified by calling EntityFieldCondition::entityCondition('entity_type', $entity_type) before executing the query. Also, by default only entities stored in SQL are supported; however, EntityFieldQuery::executeCallback can be set to handle different entity storage.


$column: A column defined in the hook_schema() of the base table of the entity.

$value: The value to test the field against. 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.


includes/entity.inc, line 891


Retrieves entities matching a given set of conditions.


public function propertyCondition($column, $value, $operator = NULL) {

  // The '!=' operator is deprecated in favour of the '<>' operator since the
  // latter is ANSI SQL compatible.
  if ($operator == '!=') {
    $operator = '<>';
  $this->propertyConditions[] = array(
    'column' => $column,
    'value' => $value,
    'operator' => $operator,
  return $this;


chaiwei’s picture

 // Initialize EntityFieldQuery
  $entity_type = 'node';
  $efq = new EntityFieldQuery();
  $efq->entityCondition('entity_type', $entity_type);
  // Query condition Using LIKE wildcard
  $efq->propertyCondition('title', "%".$form_state['values']['title']."%","LIKE");  

  // Execute query and collect results
  $result = $efq->execute();  
alexweber’s picture

This is perfectly safe as the $value parameter gets replaced with a placeholder when the query is built.

mlncn’s picture

For string comparisons, such as:

  $query = new EntityFieldQuery();
  $query->entityCondition('entity_type', 'example')
        ->propertyCondition('name', $name);
  $result = $query->execute();

The value of $name can be "CaSe INsensitivE" and it will match an entity name such as "Case insensitive".

zhangtaihao’s picture

The case sensitivity depends on the entity table collation (which is usually the default database collation). In other words, if your entity table (e.g. node) collation ends in "_ci" (i.e. case-insensitive), such as utf8_general_ci, the query will be case-insensitive.

In general, the collation of tables for a Drupal install defaults to the collation of the database created when first installing the site.

majorrobot’s picture

If your installation uses a database that doesn't offer collation, such as Mongo, you may not be able to achieve a case-insensitive EFQ without regex — which is computationally expensive.

In our experience with Mongo, if you're doing a simple query, such as seeing if a username exists, it's simpler and safer to just use a db_query() on the SQL database, instead of using an Entity Field Query.

arnoldbird’s picture

"The case sensitivity depends on the entity table collation"

Regardless of the table collation, I am finding that property conditions are handled case-insensitively. I have tried utf8_bin and latin1_general_cs, but the results are still case-insensitive.

arnoldbird’s picture

Changing the table collation with an "alter table" query didn't work for me, but changing the collation per query works, as explained here: http://drupal.stackexchange.com/a/77788
Note Alice Heaton's comment re: utf8_bin.

arnoldbird’s picture

'!=' should be listed among the possible values for $operator.

earthday47’s picture

<> is preferred

marcosdr’s picture


<> is not an allowed operator but the the function will turn != into <> for you.

drupalshrek’s picture

The following code shows how I manually keep only the results which have an accent-sensitive, but non case-sensitive match:

 * Get the node ids corresponding to a particular foreign text.
 * @return
 *   Returns an array of nids, or an empty array if not found.
function lingopolo_get_word_nids($text) {
  $nids = array();
  $query = new EntityFieldQuery();
  $query->entityCondition('entity_type', 'node')
    ->entityCondition('bundle', 'thai_word')
    ->fieldCondition('field_thai', 'value', $text);
  $result = $query->execute();
  if (!empty($result['node'])) {
    $query_nids = array_keys($result['node']);
    foreach ($query_nids as $nid) {
      // The text is not accent sensitive, so may, for example, contain "là" for
      // "la", so we only keep those which truly match. We do however do a case
      // insensitive match.
      $lp_word = new LpNode($nid);
      if (strtolower($lp_word->getTranslation()) == strtolower($text)) {
        $nids[] = $nid;
  return $nids;