Created
November 10, 2016 11:05
-
-
Save nickdavis/3123fdeba09e9f71e61ee21fc5f7a0c0 to your computer and use it in GitHub Desktop.
Advanced Custom Fields > Flexible Content field example (set programatically)
This file contains hidden or 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 (Flexible Content 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() { | |
acf_add_local_field_group( array( | |
'key' => 'group_nd_documents', | |
'title' => 'Documents', | |
'fields' => array( | |
array( | |
'key' => 'nd_documents', | |
'name' => 'nd_documents', | |
'type' => 'flexible_content', | |
'layouts' => array( | |
array( | |
'label' => 'File', | |
'name' => 'file', | |
'display' => 'row', | |
'min' => '', | |
'sub_fields' => array( | |
array( | |
'key' => 'file_title', | |
'label' => 'Title', | |
'name' => 'file_title', | |
'type' => 'text', | |
), | |
array( | |
'key' => 'file', | |
'label' => 'File', | |
'name' => 'file', | |
'type' => 'file', | |
), | |
), | |
), | |
array( | |
'label' => 'URL', | |
'name' => 'url', | |
'display' => 'row', | |
'min' => '', | |
'sub_fields' => array( | |
array( | |
'key' => 'url_title', | |
'label' => 'Title', | |
'name' => 'url_title', | |
'type' => 'text', | |
), | |
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