Support

Account

Home Forums ACF PRO Does ACF support component cloning with values, if so, how? Reply To: Does ACF support component cloning with values, if so, how?

  • I’m a little bit confused if ACF is capable of something that i’ve been trying to accomplish. What i’d like to have is a seamless syncing of cloned values throughout the site by having all the main components under options page and then cloning them into field groups.

    Right now whenever i use a clone field, the values do not get synced from the options page. So far i’ve accomplished it with this

    add_filter('acf/prepare_field', function($field){
    
        $current_screen = get_current_screen();
        if($current_screen && $current_screen->id == 'toplevel_page_theme-settings') return $field;
    
        $components = get_field('components', 'option');
    
        foreach($components as $component){
    
            if(array_key_exists($field['_name'], $component)){
                
                if(isset($field['sub_fields'])){
                       
                    // foreach($field['sub_fields'] as $field_key => $sub_field){
                    //     foreach($component[$field['_name']] as $sub_component){
                    //         if(array_key_exists($sub_field['_name'], $sub_component)){
                                
                    //             //$field['sub_fields'][$field_key]['value'] = $sub_component[$sub_field['_name']];
                    //             //consoleLog([$field, $sub_field, $sub_component[$sub_field['_name']]]);
    
                    //         }
                    //     }
                    // }
                }else{
                    $field['value'] = $component[$field['_name']];
                }
                
            }
    
        }
    
        return $field;
        
    },10,3)

    But this solution does not work with repeater fields. I am unable to save any repeater fields unless Prefix Field Names is selected but then it is not an exact clone anymore. Also i would like to leave this option untouched so that the user can have a seperate values for specific posts.

    Am i missing something? I’ve been trying to implement this feature for quite some time now but so far i’ve been unuccessful.