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
Here is a video of the issue.
Got it figured out. Was a theme conflict.