Home Forums Front-end Issues Can\'t display label choices on pages


Can\'t display label choices on pages

  • Hi! I read many post of this forum but I didn’t find an answer.

    I have a field with different values, and I need to display the label of a selected choice. I use this code but don’t work because display the value of the choice, and if I change the last “value” for “label” it display the label of the field, but no the label of the choice:(

    $field_name = "options";
    $field = get_field_object($field_name);
    echo $field['value'];

    I need to display the label “Option 1”, not the value “option1”

    Field Label: Options
    Field Name: options

    option1: Option 1
    option2 : Option 2

    Thanks in advance.

  • Well, I fixed it with whit code but…

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

    This code don’t work with checkbox and multiple values. Anyone can help me?

  • Solved reading other answers.

    A new question, how can display various field labels in different lines? I don’t know how to use echo implode function 🙁

  • that depends on what you mean by different lines. You need to output the correct HTML to separate the values. If you’re using a list

    echo '<li>',$label,'</li>';

    if you just want a break

    echo '$label,'<br />';
Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Can\'t display label choices on pages’ is closed to new replies.