6

I hhave field_something which is a select field with multiple options:

key1|Value 1
key2|Value 2

I'm trying to get the value of this field using the Entity metadata wrapper.

$wrapper->field_something->value();

This will return the key, not the value as defined in the node's fields.

Any ideas?

  • 1
    Actually, the key is the value of the field as stored in the database. If you want the value as displayed you'll have to use the Field API to get the settings for the field. I think you'll find it somewhere in what's returned from field_info_field(). – Alfred Armstrong Mar 21 '15 at 14:32
  • Why don't you use devel module to see what are the available options of the $wrapper variable? – M a m a D Mar 21 '15 at 18:20
10

You may use $wrapper->field_something->label().

1

You can try code below:

$wrapper = entity_metadata_wrapper('node', $node);
$list = $wrapper->field_machine_name->optionsList();

I hope it helps you!

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.