Home › Forums › Add-ons › Flexible Content Field › Add field to layout 'sub_fields' via php
I’m registering fields via php and the ‘parent’ field setting doesn’t seem to work for flexible_content > layouts > sub_fields. Should I use a different setting to add a re-usable field to a layout?
Thanks!

I’m not user I’m understanding how you’re adding fields to the field group.
I usually do this by generating the entire field group before registering but it sounds like you’re doing something different. Can you supply a sample of the code that you’re using?
I was trying to add the fields similar to the example in the documentation (http://www.advancedcustomfields.com/resources/register-fields-via-php). See:
acf_add_local_field(array(
'key' => 'field_1',
'label' => 'Sub Title',
'name' => 'sub_title',
'type' => 'text',
'parent' => 'group_1'
));
I’m guessing this only works for fields in groups and not for ‘sub_fields’ in flexible content layouts?
I’m trying to separate the fields within the groups and flexible layouts to make the code more manageable and possibly reuse the same field code in another instance.

Try setting ‘parent’ to the field key of the ‘layouts’ of the flex fields.
Here is the portion of an exported field group with a flex field.
'fields' => array(
array(
'key' => 'field_54fca97e88819',
'label' => __('Panels'),
'name' => 'blunt_panels',
'prefix' => '',
'type' => 'flexible_content',
'instructions' => ''
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'button_label' => __('Add Panel'),
'min' => '',
'max' => '',
'layouts' => array(
array(
'key' => '54fca987f37a3', // <= try this key as the parent
'name' => '1_column_simple',
The topic ‘Add field to layout 'sub_fields' via php’ is closed to new replies.
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.