Support

Account

Home Forums Backend Issues (wp-admin) Dynamically populating repeater fields with default values? Reply To: Dynamically populating repeater fields with default values?

  • Hi @folosophy

    You should be able to do it like this:

    function my_acf_set_repeater( $value, $post_id, $field ){
        
        $value = array();
        
        // this one should consists array of the names
        $settings_values = get_field('medication_types','option');
        
        foreach( $settings_values as $settings_value ){
            $value []= array('field_1234567890abc' => $settings_value['name_field'], 'field_abc1234567890' => '');
        }
    
        return $value;
    }
    
    // acf/load_value/name={$field_name} - filter for a specific value load based on it's field name
    add_filter('acf/load_value/key=field_582e290a22e62', 'my_acf_set_repeater', 10, 3);

    Where “field_1234567890abc” is the name field key, “field_abc1234567890” is the value field key, and “name_field” is the name field in the “medication_types” repeater.

    I hope this helps 🙂