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!