Home › Forums › Add-ons › Options Page › Dynamically populate a select subfield in a repeater field › Reply To: Dynamically populate a select subfield in a repeater field
I’m sorry too, for not being clearer.
I put a select sub-field in a repeater field. And I need to know how to write the function for it, in that it’s loading now into a sub-field.
This is how I did it before when select was a field.
//Dynamically populate a select field’s choices in ACF
function my_acf_load_field( $field )
{
// reset choices
$field[‘choices’] = array();
// load repeater from the options page
if(get_field(‘group_a_floor_plan’, ‘option’))
{
// loop through the repeater and use the sub fields “value” and “label”
while(has_sub_field(‘group_a_floor_plan’, ‘option’))
{
$value = get_sub_field(‘value’);
$label = get_sub_field(‘label’);
$field[‘choices’][ $value ] = $label;
}
}
// Important: return the field
return $field;
}
add_filter(‘acf/load_field/name=floor_plans_group_a’, ‘my_acf_load_field’);
Does anything change?
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.