Home › Forums › ACF PRO › acf add local field to flexible content › Reply To: acf add local field to flexible content
Sorry it took so long to get back to you. There were a few problems with your code, you have some extra nesting on arrays() is isn’t needed in places. Also I learned that if you’re adding fields using acf_add_local_field() that you need to add fields to a repeater, you can’t just add the repeater including the sub fields, what that means is that each individual field must be added separately.
this code works
if( function_exists('acf_add_local_field_group') ) {
acf_add_local_field_group(
array (
'key' => 'group_56ff5b11d1775',
'title' => 'add component',
'fields' => array (
array (
'key' => 'field_56ff5b1a77c75',
'label' => 'flexible content',
'name' => 'flexible_content',
'type' => 'flexible_content',
'instructions' => '',
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'button_label' => 'Add Row',
'min' => '',
'max' => '',
'layouts' => array (
array (
'key' => '56ff5b1a77c76',
'name' => 'sample_label',
'label' => 'sample label',
'display' => 'block',
'min' => '',
'max' => '',
),
),
),
),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'post',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => 1,
'description' => '',
)
);
acf_add_local_field(
array (
'key' => 'field_56ff5b1a77c79',
'label' => 'Repeatable image with optional link',
'name' => 'repeatable_imgs',
'type' => 'repeater',
'parent' => 'field_56ff5b1a77c75', //flex field key
'parent_layout' => '56ff5b1a77c76', // layout key
'row_min' => 0,
'row_limit' => '',
'layout' => 'table',
'button_label' => 'Add image',
)
);
acf_add_local_field(
array (
'key' => 'field_5237950f6c6e4',
'label' => 'url',
'name' => 'img_link_url',
'type' => 'text',
'parent' => 'field_56ff5b1a77c79',
)
);
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.