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++;
}
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.