Support

Account

Home Forums General Issues Issue registering checkbox fields via PHP

Solving

Issue registering checkbox fields via PHP

  • Hi,

    See https://www.advancedcustomfields.com/resources/register-fields-via-php/.

    I’m using this code to register a checkbox custom field:

    
    acf_add_local_field_group(array(
    	'key' => 'group_5de673be0cb12',
    	'title' => 'Reports',
    	'fields' => array(
    		array(
    			'key' => 'field_5de675a5ce3f5',
    			'label' => 'Category',
    			'name' => 'report_category',
    			'type' => 'checkbox',
    			'instructions' => '',
    			'required' => 0,
    			'conditional_logic' => 0,
    			'wrapper' => array(
    				'width' => '',
    				'class' => '',
    				'id' => '',
    			),
    			'choices' => array(
    			),
    			'allow_custom' => 1,
    			'save_custom' => 1,
    			'default_value' => array(
    			),
    			'layout' => 'vertical',
    			'toggle' => 0,
    			'return_format' => 'label',
    		),
    	),
    	'location' => array(
    		array(
    			array(
    				'param' => 'post_type',
    				'operator' => '==',
    				'value' => 'report',
    			),
    		),
    	),
    	'menu_order' => 0,
    	'position' => 'acf_after_title',
    	'style' => 'default',
    	'label_placement' => 'top',
    	'instruction_placement' => 'label',
    	'hide_on_screen' => '',
    	'active' => true,
    	'description' => '',
    ));
    

    Note the option to ‘allow_custom’ and ‘save_custom’ values is set to 1 or true (I tried both). However, after I add a a new value and save the page its on, the value is not available as an option when I create a new page.

    However, when this field is created manually in Advanced Custom Fields settings, it does show saved values/options.

    Any idea why its not saving when added with PHP above?

    Thanks!

  • Yes, this does seem to be a problem. Please submit a bug report here https://www.advancedcustomfields.com/contact/

  • Hi,

    are there any news regarding this. I just stumbled upon the same problem on one of our site. If the fields are registered via the backend, the custom values are available on new posts. When registering the field via php, custom values only are available for the posts, there were created on.

    Thanks!

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Issue registering checkbox fields via PHP’ is closed to new replies.