You are here

function entity_metadata_field_query in Entity API 7

Callback for querying entities by field values. This function just queries for the value of the first specified column. Also it is only suitable for fields that don't process the data, so it's stored the same way as returned.

2 string references to 'entity_metadata_field_query'
entity_metadata_field_default_property_callback in modules/field.info.inc
Callback to add in property info defaults per field instance.
entity_property_query in includes/entity.property.inc
Queries for entities having the given property value.

File

modules/callbacks.inc, line 1097
Provides various callbacks for the whole core module integration.

Code

function entity_metadata_field_query($entity_type, $property, $value, $limit) {
  $query = new EntityFieldQuery();
  $field = field_info_field($property);
  $columns = array_keys($field['columns']);
  $query
    ->entityCondition('entity_type', $entity_type, '=')
    ->fieldCondition($field, $columns[0], $value, is_array($value) ? 'IN' : '=')
    ->range(0, $limit);
  $result = $query
    ->execute();
  return !empty($result[$entity_type]) ? array_keys($result[$entity_type]) : array();
}