What you will need to do is when you define the Select field, select the Return Format as 'Both (Array)'.
This means you can then call your field as a variable and echo the label and value:
$field = get_field('license_type');
$value = $field['value'];
$label = $field['label'];
echo 'Value: ' . $value . '<br>' . 'Label: ' . $label;
Hope this helps.
Try this, which worked for me:
<?php
$fields = get_field_objects(); // I changed from get_fields()
if( $fields ): ?>
<ul>
<?php
// I changed $value to $field (i.e. the variable name)
foreach( $fields as $name => $field ):
if (stripos($name, 'isbn') !== false) : ?>
<li><b><?php echo $field['label']; ?></b> <?php echo $field['value']; ?></li>
<?php endif;
endforeach; ?>
</ul>
<?php endif; ?>
So referring to the in the code, $field is the field label (e.g. "Book ISBN"), and $field['label'] is the field value. Note though, that the field value could be an $field['value'], so simply array-ing it would (likely throw a PHP warning and) give you a "Array".echo
See https://www.advancedcustomfields.com/resources/get_field_objects/ if you need help with the function.get_field_objects()
PS: If you only want to get the label of a single field and not all fields (of the current/target post/user/etc.), you can use instead.get_field_object()
From the ACF documentation there are few settings to keep in mind. Do you want both label and value stored or one of them. Do we have default value ? Do we allow null ?
From the documentation Allow Null option - If selected, the select list will begin with an empty choice labelled “- Select -“. If using the Stylized UI setting, this choice will be replaced by a ‘x’ icon allowing you to remove the selected value(s).
Here is an example of a post loop with select field
get_header();
if(have_posts()):
while(have_posts()): the_post();
// If select is array ( value and label)
$color = get_field('color');
if(isset($color['value'])):
var_dump($color['value'].' '.$color['label']);
endif;
// If select is label or value
$color = get_field('color');
if(isset($color)):
var_dump($color);
endif;
endwhile;
endif;
get_footer();
For multi select field we need to loop our values.
get_header();
if(have_posts()):
while(have_posts()): the_post();
echo '<div>';
the_title();
echo '</br>';
$colors = get_field('colors');
if(isset($colors)):
echo implode(',',$colors); // or use foreach
foreach($colors as $color):
echo $color;
endforeach;
endif;
echo '</br>';
$sizes = get_field('sizes');
if(isset($sizes)):
echo implode(',',$sizes); // or use foreach
foreach($sizes as $size):
echo $size;
endforeach;
endif;
echo '</div>';
endwhile;
endif;
get_footer();
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.