Support

Account

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.