Skip to content

Instantly share code, notes, and snippets.

@nickdavis
Created November 10, 2016 10:59
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nickdavis/b57790c9453d16af554837069ea1d9ec to your computer and use it in GitHub Desktop.
Save nickdavis/b57790c9453d16af554837069ea1d9ec to your computer and use it in GitHub Desktop.
Advanced Custom Fields > Repeater field example (set programatically)
<?php
add_action( 'acf/init', 'nd_acf_add_local_field_groups' );
/**
* Add Advanced Custom Fields programatically (Repeater field).
*
* @link https://www.advancedcustomfields.com/resources/register-fields-via-php/
* @link https://support.advancedcustomfields.com/forums/topic/register-two-locations-via-php-doesnt-work/
* @link https://support.advancedcustomfields.com/forums/topic/adding-additional-layout-to-flexible_content-field-in-child-theme/
*
* @return void
*/
function nd_acf_add_local_field_groups() {
/**
* Repeater field
*/
acf_add_local_field_group( array(
'key' => 'group_nd_documents',
'title' => 'Documents',
'fields' => array(
array(
'key' => 'nd_documents',
'name' => 'nd_documents',
'type' => 'repeater',
'instructions' => 'URL overrides File, if set',
'sub_fields' => array(
array(
'key' => 'title',
'label' => 'Title',
'name' => 'title',
'type' => 'text',
),
array(
'key' => 'file',
'label' => 'File',
'name' => 'file',
'type' => 'file',
),
array(
'key' => 'url',
'label' => 'URL',
'name' => 'url',
'type' => 'url',
),
),
'button_label' => 'Add Document',
'min' => '',
'max' => '',
),
),
'location' => array(
array(
array(
'param' => 'page_ancestor',
'operator' => '==',
'value' => 6,
),
array(
'param' => 'page_type',
'operator' => '==',
'value' => 'no_children',
),
),
),
'menu_order' => 6,
'position' => 'acf_after_title',
) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment