1

I'm trying to get a CCK text field's value using node_load() - the code goes like $nodeObject->field_name['und']['0']['value'];

Is there a simpler built-in function like get_cck_field_value(node $nodeObject) that I can use, or do I write it myself?

  • I think there is nothing so. Please share if you make one. – niksmac Apr 11 '12 at 11:30
9

You can use field_get_items() like this:

field_get_items('node', $node, $field_name);

Also see What's best practice when working with the language['und']?.

  • 1
    Thank you for the link you provided field_get_items() is great, and so is entity_metadata_wrapper()... does any of them include an additional call to the DB? I shouldn't think so, but still... – Aditya M P Apr 11 '12 at 12:31
  • @harijari Nice finding – niksmac Apr 13 '12 at 4:46
1

You can also use methods provided by Entity API module:

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

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.