Display all values of custom a field created with ACF on a page

The get_field_object ACF function can be used to get info and options for a specific field.

First you need the field key of the specific field you wish to output. When editing a field group, click on the screen options tab at the top of the page. You should see an option to toggle the display of the field key (it is hidden by default to save space):

Field Key

Once you have the key, you can load the field object and output its values:

$field_key = "field_5039a99716d1d";
$field = get_field_object($field_key);

if( $field )
{
    echo '<select name="' . $field['key'] . '">';
        foreach( $field['choices'] as $k => $v )
        {
            echo '<option value="' . $k . '">' . $v . '</option>';
        }
    echo '</select>';
}

Leave a Comment

tech