Drupal – Get CCK Allowed Value Label

We can create a CCK selection list or checkboxes field with a list of allowed values in key|value pair. normally when you retrieve a node content, what you get is only the key instead of the value.

Suppose we have a content type called Silly Question(silly_question) with a field called Option(field_option) which has the following allowed values.

abc|ABC
def|DEF
ghi|GHI

 

To get key the value of a specific key in code level, try the following piece of code.

$field = content_fields('field_option', 'silly_question');
$allowed_values = content_allowed_values($field);

// print ABC
print $allowed_values['abc'];

 

Done =)

Reference: How to print label of key|label

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.