WordPress.org

Ready to get started?Download WordPress

Forums

Advanced Custom Fields
Multiple checkbox values not selected (1 post)

  1. Michael Cannon
    Member
    Posted 2 years ago #

    $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/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

  • RSS feed for this topic
  • Started 2 years ago by Michael Cannon
  • This topic is not resolved
  • WordPress version: 3.3.1