Support

Account

Home Forums General Issues Save individual field group automatically to plugin using save_json Reply To: Save individual field group automatically to plugin using save_json

  • Hi Michael,

    So there would be two things you need to consider. First is to save your fieldgroup JSON in your own location and secondly to tell ACF to also look in your location for JSON files.

    For the second part there’s the function you already seem to have in place so that’s good 🙂

    As for the saving part there is only one save point.. I think in theory you could maybe do what you’re asking. Create your own save_json filter on save_post but that might be too late as well..

    I’m not sure wether ACF checks the save path on each save tho or just go fetch the save path directly from the DB.. if it does check each time you might even be able to do a check for the $_POST variables inside the function and figure out if you’re on the specific field group and change the path accordingly.

    
    add_filter('acf/settings/save_json', 'my_acf_json_save_point');
     
    function my_acf_json_save_point( $path ) {
        
    //If you have wp_debug active this will put the entire $_POST in your debug.log file in wp-content. 
    error_log(print_r($_POST, true));
    
    if( $_POST['somethingsomething'] )
        $path = get_stylesheet_directory() . '/my-custom-folder';
        
        
        // return
        return $path;
        
    }