Support

Account

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?