How can I get all options for a fields?
For example, There is a field with 3 options in allowed values, like option1, option2, option3.Is there any function which receive the field name and returns selected values not a keys ?
With this just return key of selected opinion
print ($node->field_opinion['und'][0]['value'])
You can do this using list_allowed_values function :
$key = $node->field_opinion['und'][0]['value']; $options = list_allowed_values('field_opinion'); $label = $options[$key];
The accepted answer did not work for my use case, I had to do the following:
$key = // db_select('node'...
$field_definition = field_info_field('field_name');
$options = list_allowed_values(field_definition, 'node');
$label = $options[$key];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.