0

Say I want to fetch a single value from the node table: I could use the database API:

$value = db_query('
  SELECT title FROM {node} WHERE nid = :nid
', array(':nid' => $nid,))->fetchField();

What is the equivalent using an entity metadata wrapper?

Thanks.

0
0

Well you could use:

$node = node_load($nid);
$wrapper = entity_metadata_wrapper('node', $node);
$title = $wrapper->title->value();

But if that's literally all you need to get from the node, an EntityMetadataWrapper is overkill in my opinion. Just use:

$node = node_load($nid);
$title = $node->title;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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