WordPress.org

Support

Support » Plugins and Hacks » Advanced Custom Fields » [Plugin: Advanced Custom Fields] Multiple checkbox values not selected

[Plugin: Advanced Custom Fields] Multiple checkbox values not selected

  • $field[‘value’] for core/fields/checkbox.php in function create_field isn’t an array itself, but a CSV. As such, the in_array() call to set selected will never work. The fix is to convert the CSV to an array like below.

    function create_field($field)
        {
            // defaults
            if(empty($field['value'])) {
                $field['value'] = array();
            } else {
                $field['value'] = explode(',', $field['value']);
            }
        ...
        }

    Also, the correct way to check a checkbox is $selected = 'checked="checked"'; not $selected = 'checked="yes"';.

    Great extension, especially now that I have the ability to pull in configurations via PHP code dynamically based upon my arbitrary conditions.

    http://wordpress.org/extend/plugins/advanced-custom-fields/

  • The topic ‘[Plugin: Advanced Custom Fields] Multiple checkbox values not selected’ is closed to new replies.
Skip to toolbar