Support

Account

Home Forums General Issues multiselect how to output value and label Reply To: multiselect how to output value and label

  • I was able to figure it out. If someone also need:

    $labels = array();
    $field = get_field_object( ‘especie_de_acao’ );
    $values = get_field(‘especie_de_acao’);
    foreach ($values as $value) {
    $labels[] = $field[‘choices’][ $value ];
    }
    $i = 0;
    $len = count($labels);

    if ($len == 0) { echo ‘<strong style=”color: red;” >’; echo “(especifique um tipo de ação)”; echo ““;}
    elseif ($len == 1) {

    echo ““; echo $labels[0]; echo ““;

    } else {
    foreach ($labels as $label) {

    if ($i == 0) {
    echo ““; echo $label; echo ““; echo ” c/c “; //first
    } elseif ($i == $len – 1) {
    echo ““; echo $label; echo ““; echo “,”; //last
    } else {
    echo ““; echo $label; echo ““; echo “, c/c “;
    }
    $i++;
    }
    }

    if ($len == 0) { echo “(especifique um tipo de ação)”;}
    elseif ($len == 1) {

    echo $values[0];

    } else {
    foreach ($values as $value) {
    if ($i == 0) {
    echo $value; echo “, “; //first
    } elseif ($i == $len – 1) {
    echo ” e “; echo $value; echo “,”; //last
    } else {
    echo $value; echo “, “;
    }
    $i++;
    }
    }