Home › Forums › Bug Reports › Checkbox and Select do not return Value
I am adding next choices:
[divi_shortcode id=”243391″] : Citrus
[divi_shortcode id=”243555″] : Citrus new
and select Return – Value and when I use Radio button it works perfectly find (it returns a short code that is being pulled through a dynamic feature to a Divi text box and as a result shows the layout associated with it from Divi Library)
However when I do exactly the same thing in Checkbox or Select it returns a label: “Citrus” line. I am really puzzled what’s happening, I need Choose multiple functionality so I can not continue using Radio button but I can not make the other 2 work. Help!
What settings are you using for either the checkbox or select field?
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.
Thank you for your help! The thing is that I am using Divi and pull custom field return “item” (value or label) through Divi dynamic fields. I saw a lot of explanations online of what could be wrong but they all include code like you shared but I don’t have access to that level of customization.
The reason it is not working in divi is what I mentioned about the way the value is stored.
checkbox fields and multi-select fields are stored in the DB as serialize arrays. This is probably the reason that it’s not working.
I do not know anything about divi or if it can work with advanced fields in ACF. I would start with their documentation or searching for information on how to use complex SCF fields in divi. You need to figure out how to loop over an array value returned by a field in divi.
A simple work-a-round would be to create multiple single select fields like your original field, but that would not be my choice.
Sorry, I can’t help more. I do not use divi or any theme framework when I build sites because they are either too limiting or turn simple things into complex tasks when you need to work outside of the box that they create.
That makes sense, I am still confused why it was so easy to make it work for Radio button but exactly the same approach returns label instead of value for the Check boxes and Select. That’s why I thought to ask here because it feels like I got it right for one of them so it should work the same for the others? I also had no issue with any other custom fields + Divi such as image, text block, etc.
You must be logged in to reply to this topic.
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’re reaching out to our multilingual users to ask for help in translating ACF 6.1. Help make sure the latest features are available in your language here: https://t.co/TkEc2Exd6U
— Advanced Custom Fields (@wp_acf) May 22, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.