Home › Forums › Bug Reports › Checkbox and Select do not return Value › Reply To: Checkbox and Select do not return Value
Yes, return value and I also wanted to double check the choices that you are adding for the field so that I can test it or figure out what the cause is.
Also, now that I’m thinking about it.
You are changing from a field that stores 1 value to a field that can store multiple values. Before editing a post this field will still only have one value and posts that have been edited might have multiple values. This means that it is possible (but I’m not sure) that when you get the value of the field it may or may not return an array. So you need to check that.
$values = get_field('field-name');
if (!empty($values) && !is_array($values)) {
$values = array($values);
}
if (!empty($values)) {
foreach ($values as $value) {
echo do_shortcode($value);
}
}
I would probably also not use shortcodes for values and I would just use the ID as the value.
243391 : Citrus
243555 : Citrus new
Then the above becomes
echo do_shortcode('[divi_shortcode id="'.$value.'"]');
I would probably actually create an acf/format_value filter instead of coding this for every field.
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.