7

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?

2
  • 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(). Mar 21, 2015 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, 2015 at 18:20

2 Answers 2

13

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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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