-
-
Save mrpsiho/81b57e3c1265fa653678c6be89a5faab to your computer and use it in GitHub Desktop.
Example of dynamically populated choices for ACF select 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
add_filter( 'acf/load_field', 'my_plugin_get_proper_form_templates', 10, 1 ); | |
function my_plugin_get_proper_form_templates($field) { | |
if ( 'select_form_tmpl' === $field['name'] ) { | |
$forms_cfg = my_plugin_get_form_fields_cfg(); // external function, we get data from here | |
$choices = []; | |
if (array_keys($forms_cfg)) { | |
foreach (array_keys($forms_cfg) as $tmpl_name) { | |
$choices[$tmpl_name] = $forms_cfg[$tmpl_name]['label']; | |
} | |
} | |
$field['choices'] = $choices; | |
} | |
return $field; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment