I have a Template node that holds an Entity Reference multivalue field to a series of other nodes, all referenced nodes of the same type. The referenced nodes have a text field whose value I need to get.

In template node I have a computed field that do some calculations using the values from referenced nodes.

Now I have:

$tpl = field_get_items($entity_type, $entity, 'field_plan_tpl');
$values = array();
foreach ($tpl as $field_item) {
  $values[] = node_load($field_item['target_id'])->field_some_field[LANGUAGE_NONE][0]['value'];

How can I load the referenced entities in order to get field values, using entity_metadata_wrapper()?


1 Answer 1


entity_metadata_wrapper() has you covered, the entities will be lazy-loaded as you'd expect:

$wrapper = entity_metadata_wrapper($entity_type, $entity);

foreach ($wrapper->field_plan_tpl as $related_entity) {
  $foo_field_value = $related_entity->field_foo->value();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.