Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using the wordpress Advanced Custom Fields plugin.

This question is about the select field, and in the documentation only tells me how to output the value, not the label/name.

I can't see this functionally in the documentation and was wondering if anyone had any ideas?

For example, to create Select field content, you simple do this...

gb : English
fr : Français
it : Italiano
de : Deutsch
pt : Português
es : Español
nl : Nederlands
be : Belgian
dk : Dansk
fi : Suomi
no : Norske
cz : Český
pl : Polski
hu : Magyar
ch : Schweiz
at : Österreich
eu : International


Then to output this, you write this...

<?php the_field('language'); ?>


For example if I select Polski in my post editor, the PHP will echo this value...

pl


I'm wondering if its possible to echo the label, I also want to be able to echo Polski, as well as the value pl.

If anyone knows of any documentation on how to do this or if you could help with a solution that would be most awesome.

Thanks in advance.

share|improve this question

3 Answers 3

Throwing the solution here for better reading.

$field = get_field_object('field_name');
$value = get_field('field_name');
$label = $field['choices'][ $value ];

The value in $label will be the label related to the value set in $value.

share|improve this answer

The get_field_object() function requires the field KEY not the field NAME. See docs: http://www.advancedcustomfields.com/resources/functions/get_field_object/

So it should looks something like this...

$field = get_field_object('field_53d27f5599979');
$value = get_field('field_myfield');
$label = $field['choices'][ $value ];

You can find the field key by clicking on "Screen Options" > "Show Field Key" and it should appear next to the field type. See attached animated gif-cast below.

Show Field Key

share|improve this answer
up vote 1 down vote accepted

Please see this thread for answer...

http://support.advancedcustomfields.com/discussion/comment/12690#Comment_12690

share|improve this answer
    
That page doesn't exist anymore unfortunately. A good reason to summarize in your answer.... –  Jake Jan 16 at 23:49
    
    
Would have like to have seen that... –  mantis Feb 26 at 13:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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