Last active
January 19, 2017 07:56
-
-
Save ville6000/cd7f75c994b08b3fb6ab352c805ad580 to your computer and use it in GitHub Desktop.
Populate ACF select field's choices dynamically
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 | |
function acf_load_color_scheme_field_options( $field ) { | |
$field['choices'] = array(); | |
$options = fetch_my_choises(); // Fetch your choises from somewhere | |
if ( is_array( $options ) ) { | |
foreach ( $options as $option ) { | |
$field['choices'][ $option ] = $option; | |
} | |
} | |
return $field; | |
} | |
add_filter( 'acf/load_field/name=color_scheme', 'acf_load_color_scheme_field_options' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment