Hello,
I used the below ACF tutorial to dynamically populate select fields from a repeater field in an option page. It works intermittently, but then stops working altogether.
https://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/#populating-choices-from-a-repeater-field
Here is the code I’m using:
function acf_color_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_color_choices');
add_filter('acf/load_field/name=secondary_color', 'acf_color_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
In short, the values dynamically pull into select fields within the ACF > Field Groups screen, but they do not show up in the select fields themselves. Here is a video of the issue:
https://app.screencast.com/1zAsvjt2NE6Zn
Thanks for your help in advance.