Hi, very new to ACF and I’m trying to get the values (i think) of the field group choices.
I have the choices:
example-student : Student
example-teacher : Teacher
example-principal : Principal
I want to get the second value of these choices (Student, Teacher, Principal) instead of the first.
I’ve tried a number of things looking at the get_field
documentation but I can’t seem to get what I need.
Here’s my code:
$people= get_field('people');
if (is_array($people) && count($people))
{
print('<h5>More information for...</h5>' . "\n" . '<ul>' . "\n");
foreach ($people as $slug)
{
print(' <li><a href="/' . $slug . '/" class="audience ' . $slug . '">' .
ucwords(str_replace('-',' ', $slug)) . '</a></li>' . "\n");
}
print('</ul>' . "\n");
}
This will get me a list of links with Example Student
.. etc. instead of just Student
.. etc.
Thanks,
$field['choices']
gives me:
Array ( [example-student] => Student
[example-teacher]] => Teacher
[example-principal] => Principal
)
but
$label = $field['choices'][ $value ];
throws an exception and breaks the site
Was able to figure this out:
$choice_field= get_field('my_field_name');
$field['choices'][$choice_field[0]]
Gives me what i need,
$field = get_field_object('your_field_name');
is the field variable, forgot this.