Hello,
I have added a checkbox with the field name of tabs_used using the following choices
Overview : Overview
Experience : Experience
Publications : Publications
Community : Community
Recognition : Recognition
I would like to display the value or label for a particular checkbox only but cannot seem to get it to work per the documentation.
Here’s what I have and no return value is shown:
<?php
$field = get_field_object('tabs_used');
$value = get_field('tabs_used');
$label = $field['Experience'][ $value ];
?>
<h2><?php echo $label; ?></h2>
I have changed the $field[] section to ‘choices’ but this give me an error “Warning: Illegal offset type in”
How can I display the value or label of only one particular checkbox choice in my checkbox options?
Still no response here or via email…
I’ve been tearing my hair out on this – and I’m sure by now you’ve found a solution or a workaround, but this is what worked for me.
The situation seems to be that $value returns an array rather than a value, so you need to return the first element in that array, like this:
<?php
$field = get_field_object('tabs_used');
$value = get_field('tabs_used');
$label = $field['Experience'][ $value[0] ];// adding the [0] to your code
?>
<h2><?php echo $label; ?></h2>
Hope that works for you!