Last active
December 28, 2016 05:17
-
-
Save kjbrum/5247e4b191480d21815e to your computer and use it in GitHub Desktop.
Add custom options to an ACF field.
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 | |
/** | |
* ACF Load Field Choices. | |
* | |
* @param array $field The field that we are going to add options to | |
* @return array $field The field we modified | |
*/ | |
function acf_load_field_choices( $field ) { | |
// Reset choices | |
$field['choices'] = array(); | |
// Get all the child pages | |
$child_pages = get_children( array( 'post_parent' => 1, 'post_type' => 'page' ) ); | |
// Add our child pages as options | |
foreach( $child_pages as $child ) { | |
$field['choices'][$child->post_name] = $child->post_title; | |
} | |
return $field; | |
} | |
add_filter( 'acf/load_field/name=field_name', 'acf_load_field_choices' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment