8 entity.inc entity_load($entity_type, $id, $reset = FALSE)
7 common.inc entity_load($entity_type, $ids = FALSE, $conditions = array(), $reset = FALSE)

Load entities from the database.

The entities are stored in a static memory cache, and will not require database access if loaded again during the same page request.

The actual loading is done through a class that has to implement the DrupalEntityControllerInterface interface. By default, DrupalDefaultEntityController is used. Entity types can specify that a different class should be used by setting the 'controller class' key in hook_entity_info(). These classes can either implement the DrupalEntityControllerInterface interface, or, most commonly, extend the DrupalDefaultEntityController class. See node_entity_info() and the NodeController in node.module as an example.

@todo Remove $conditions in Drupal 8.


$entity_type: The entity type to load, e.g. node or user.

$ids: An array of entity IDs, or FALSE to load all entities.

$conditions: (deprecated) An associative array of conditions on the base table, where the keys are the database fields and the values are the values those fields must have. Instead, it is preferable to use EntityFieldQuery to retrieve a list of entity IDs loadable by this function.

$reset: Whether to reset the internal cache for the requested entity type.

Return value

An array of entity objects indexed by their ids. When no results are found, an empty array is returned.

See also





9 calls to entity_load()
comment_load_multiple in modules/comment/comment.module
Load comments from the database.
EntityLoadTestCase::testEntityLoadConditions in modules/simpletest/tests/entity_crud.test
Tests the functionality for loading entities matching certain conditions.
FileTaxonomyTermTestCase::_testTermFile in modules/file/tests/file.test
Runs tests for attaching a file field to a taxonomy term.
file_file_download in modules/file/file.module
Implements hook_file_download().
file_load_multiple in includes/file.inc
Loads file objects from the database.

... See full list

1 string reference to 'entity_load'
DrupalDefaultEntityController::attachLoad in includes/entity.inc
Attaches data to entities upon loading.


includes/common.inc, line 7958
Common functions that many Drupal modules will need to reference.


function entity_load($entity_type, $ids = FALSE, $conditions = array(), $reset = FALSE) {
  if ($reset) {
  return entity_get_controller($entity_type)->load($ids, $conditions);


"Instead, it is preferable to use EntityFieldQuery to retrieve a list of entity IDs loadable by this function."


  $query = new EntityFieldQuery();

    ->entityCondition('entity_type', 'artwork', '=')
    ->propertyCondition('type', 'painting', '=');

  $result = $query->execute();
  $aids = array();
  foreach($result['artwork'] as $record) {
    $aids[] = $record->aid;
  $artworks = entity_load('artwork', $aids);

You can easily get the ids from the query by getting the returned array's keys:

$ids = array_keys($result['artwork']);

->propertyCondition('relation_type', 'painting', '=');

Is it possible to use entity load with fields?? I tried but i can't make it work

Yeah, put your fields in $conditions as array like this :
$items = entity_load('node', FALSE, array('type' => 'article', 'title' => 'mytitle'));

You would want to use an EntityFieldQuery instead. See http://drupal.org/node/1343708

1) ...that calling entity_load() can cause that entity's cache to be updated (this happens in DrupalDefaultEntityController::load)

2) ...that if you want to reload of revert an entity to load it as it is on the database right now, not as it was when previously loaded or as it is in memory after being editted in memory, you don't need to use the final 'true' parameter which can have unintended consequences wiping caches of other entities of the same type, you can use entity_load_unchanged()

This says that the return value contains "An array of entity objects indexed by their ids. When no results are found, an empty array is returned."

Can anyone tell me where the properties of the entity object are documented? I've searched the API documentation, as well as Google, and been unable to find this so far. Thanks!

There are no specific properties for entities, they will depend on what's defined in the hook_entity_info() of the module that implements the entity type. Other modules may add into the object through hooks, so what the entity object looks like will depend on what type of entity you're working with, fields defined for the entity, and the combination of modules that may hook in.

If you just want to look up a single entity ID, make sure you put it in as an array (at least in Drupal 7). I didn't read the parameters carefully enough, and that caused me a bit of grief. :P

= entity_load('field_collection_item', array('single_entity_id'));

Your advice that a single entity ID had to be an array just solved a headache for me. Thank you.

Use entity_load_single() to load only one entity.

DrupalDefaultEntityController::load as clicking on load currently does a search for all load functions.

If $conditions are deprecated, what would be the preferred way of loading a specific old revision of an entity.

For example, what is the non-conditions way of doing this:

= entity_load('node', array(), array('vid' => 123));

EntityFieldQuery() can return revisions using age(), however it doesn't return full nodes so you then have to load the nodes, and then you need conditions, unless I'm missing something somewhere.

I will track down the issue where $conditions are removed and ask there too when I get some time.

To answer my own question: entity_revision_load().
In drupal 8 it is in core: entity_revision_load()
In drupal 7 it is in the Entity API module: entity_revision_load()

$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'my_bundle_name')
->fieldCondition('field_id', 'value', $id, '=')
->range(0, 1);

$result = $query->execute();
if (isset($result['node'])) {
$nid = array_keys($result['node']);
$node = entity_load_single('node', $nid);
drupal_set_message('The nid is ' . $node->nid);

The functionality of this function has changed in Drupal 8. In Drupal 8 the entity_load will return a single entity so you don't need to use PHP reset function or other function go get a single Entity.
Instead there will be a new function in Drupal 8 called entity_load_multiple to load multiple entities if you need it just like user_load_multiple and node_load_multiple.
This can be seen here.

For Paragraphs

= entity_load('paragraphs_item', array('single_entity_id'));