Created
November 10, 2016 10:59
-
-
Save nickdavis/b57790c9453d16af554837069ea1d9ec to your computer and use it in GitHub Desktop.
Advanced Custom Fields > Repeater field example (set programatically)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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