1.20.x entity.query.inc public EntityFieldQuery::execute()

Executes the query.

After executing the query, $this->orderedResults will contain a list of the same entity ids in the order returned by the query. This is only relevant if there are multiple entity types in the returned value and a field ordering was requested. In every other case, the returned value contains everything necessary for processing.

Return value

Either a number if count() was called or an array of associative arrays: of the entity ids. The outer array keys are entity types, and the inner array keys are the relevant ID. (In most cases this will be the entity ID. The only exception is when age=FIELD_LOAD_REVISION is used and field conditions or sorts are present -- in this case, the key will be the revision ID.) The entity type will only exist in the outer array if results were found. The inner array values consist of an object with the entity_id, revision_id and bundle properties. To traverse the returned array:

    foreach ($query->execute() as $entity_type => $entities) {
      foreach ($entities as $entity_id => $entity) {
  

Note if the entity type is known, then the following snippet will load the entities found:

    $result = $query->execute();
    if (!empty($result[$my_type])) {
      $entities = entity_load($my_type, array_keys($result[$my_type]));
    }
  

File

modules/entity/entity.query.inc, line 765
Entity query API.

Class

EntityFieldQuery
Retrieves entities matching a given set of conditions.

Code

public function execute() {
  // Give a chance to other modules to alter the query.
  backdrop_alter('entity_query', $this);
  $this->altered = TRUE;

  // Initialize the pager.
  $this->initializePager();

  // Execute the query using the correct callback.
  $result = call_user_func($this->queryCallback(), $this);

  return $result;
}