ACF's Documentation
https://www.advancedcustomfields.com/resources/register-fields-via-php/
Support Response Which Contained Example Code
https://support.advancedcustomfields.com/forums/topic/acf-add-local-field-to-flexible-content/
<?php | |
return [ | |
'group_btm_flex_default', | |
[ | |
'title' => 'Page Content Builder', | |
'label' => 'Add content', | |
'location' => [ | |
[ | |
[ | |
'param' => 'post_type', | |
'operator' => '==', | |
'value' => 'page', | |
], | |
], | |
], | |
'menu_order' => 0, | |
'position' => 'normal', | |
'style' => 'default', | |
'label_placement' => 'top', | |
'instruction_placement' => 'label', | |
'hide_on_screen' => [ | |
'comments', | |
'excerpt', | |
'discussion' | |
], | |
'fields' => [ | |
[ | |
'key' => 'field_btm_content_layout', | |
'name' => 'field_btm_content_layout', | |
'label' => 'Content Layout', | |
'type' => 'flexible_content', | |
'required' => 0, | |
'button_label' => 'Add content', | |
'layouts' => [ | |
[ | |
'key' => 'field_btm_panel', | |
'name' => 'field_btm_panel', | |
'label' => 'Panel', | |
'display' => 'block', | |
'min' => '', | |
'max' => '', | |
] | |
] | |
] | |
] | |
], | |
[ | |
[ | |
'key' => 'field_btm_panel_image', | |
'label' => 'Panel Image', | |
'type' => 'image', | |
'required' => 0, | |
'min_width' => 500, | |
'min_height' => 300, | |
'return_format'=> 'id', | |
'parent' => 'field_btm_content_layout', //flex field key | |
'parent_layout'=> 'field_btm_panel' // layout key | |
], | |
[ | |
'key' => 'field_btm_panel_content', | |
'label' => 'Panel Content', | |
'type' => 'wysiwyg', | |
'required' => 0, | |
'parent' => 'field_btm_content_layout', //flex field key | |
'parent_layout'=> 'field_btm_panel' // layout key | |
] | |
] | |
]; | |
?> |
<?php | |
if (function_exists('create_meta_fields')) { | |
$acf_configs = []; | |
$acf_configs[] = include('acf-panel-config.php'); | |
foreach ($acf_configs as $config) { | |
create_meta_fields($config); | |
} | |
} | |
?> |
<?php | |
if (!function_exists('create_meta_fields')) { | |
function create_meta_fields($params) { | |
$groupname = $params[0]; | |
$group = $params[1]; | |
$fields = $params[2]; | |
add_action( 'init', function() use ($groupname, $group, $fields) { | |
if ( function_exists( 'acf_add_local_field_group' ) ) { | |
$group['key'] = $groupname; | |
acf_add_local_field_group($group); | |
} | |
if ( function_exists( 'acf_add_local_field' ) ) { | |
foreach ($fields as $field) { | |
$field['name'] = $field['key']; | |
if (!isset($field['parent'])) { | |
$field['parent'] = $groupname; | |
} | |
acf_add_local_field($field); | |
} | |
} | |
}); | |
} | |
} | |
?> |
ACF's Documentation
https://www.advancedcustomfields.com/resources/register-fields-via-php/
Support Response Which Contained Example Code
https://support.advancedcustomfields.com/forums/topic/acf-add-local-field-to-flexible-content/