drupal7 Get field values using Entity metadata wrapper

entity metadata wrapper

This entity metadata wrapper class is provided by the Entity API module. By using entity metadata wrapper class we can set new fields data dynamically to node and also we can get node fields data by using entity metadata wrapper class

Retrieve values from a node using entity metadata programmatically.

To retrieve field values from node first you need to pass node id in entity metadata wrapper then wrapper calls can store all fields data in the object. By using this object get all fields data

Retrieve string fields data using entity metadata wrapper

Entity wrapper code and example


$wrapper = entity_metadata_wrapper('node', $node);
$wrapper->field_vg_data->value(); // $wrapper->ccl_field_name->value();

Here $wrapper is an object where storing the node data into an object. By using this $wrapper variable we can get string CCK fields data like above

 Syntax: $wrapper->field_name->value() 

Retrieve integer(target_id) fields data using entity metadata wrapper

Entity wrapper code and example

$wrapper = entity_metadata_wrapper('node', $node);
$wrapper->field_vg_data->raw(); // $wrapper->ccl_field_name->value(); 

Here $wrapper is an object where storing the node data into an object. By using this $wrapper variable we can get integer or entity reference CCK fields data like above.

raw() function used to get the integer values.

If you assigned any entity reference to this field, must call raw() function to get integer values

 Syntax: $wrapper->field_name->raw() 
start a project with us