Home › Forums › General Issues › Dynamic Select Field not Populating › Reply To: Dynamic Select Field not Populating
Hello,
I used the this ACF tutorial/code to dynamically populate select fields from a repeater field in an option page. It works intermittently, but then stops working altogether. The labels and values dynamically populate the select field inside the ACF > Field Groups screen, but they do not appear at all inside the Options page select.
Here is the code I’m using:
function acf_load_color_field_choices( $field ) {
// Reset choices
$field['choices'] = array();
// Check to see if Repeater has rows of data to loop over
if( have_rows('global_colors', 'option') ) {
// Execute repeatedly as long as the below statement is true
while( have_rows('global_colors', 'option') ) {
// Return an array with all values after the loop is complete
the_row();
// Variables
$value = get_sub_field('global_color');
$label = get_sub_field('global_color_name');
// Append to choices
$field['choices'][ $value ] = $label;
}
}
// Return the field
return $field;
}
add_filter('acf/load_field/name=primary_color', 'acf_load_color_field_choices');
add_filter('acf/load_field/name=secondary_color', 'acf_load_color_field_choices');
Repeater field name is global_colors
Subfields are global_color
and global_color_name
Select Field Names to grab the repeater field(s) are:
primary_color
and secondary_color
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.