Home › Forums › General Issues › Register fields via PHP > Repeater
Register fields via PHP, awesome! But how to add a repeater field?
Would love to see this added to the documentation.
You could create a Repeater Field in Backend use the Export Tool to see how you can do it. A Repeater with a textfield looks like this.
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array(
'key' => 'group_5c18f89ca825f',
'title' => 'repeater',
'fields' => array(
array(
'key' => 'field_5c18f8a29941c',
'label' => 'repeaterField',
'name' => 'repeaterFieldName',
'type' => 'repeater',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'collapsed' => '',
'min' => 0,
'max' => 0,
'layout' => 'table',
'button_label' => '',
'sub_fields' => array(
array(
'key' => 'field_5c18f8ba9941d',
'label' => 'repeaterField-TextField',
'name' => 'repeaterfield-textfieldName',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
),
),
),
'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' => '',
));
endif;
If you dont want to create this repeater inside you live/devlopment page, create a seprate wordpress installation local.
– Create the fields in a separate instalation
– Copy/Paste the PHP Code
– Export the json (for later)
If you have to make changes later. Import the json in the separate installation, make the changes. Copy/Paste the php, and export the json also.
Thanks @enky that’s exact what I needed, works like a charm!
The topic ‘Register fields via PHP > Repeater’ 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.