0

I am using Advance Custom Fields local json so I can synchronise my forms across different environments.

See my function below, with var dump outputs in comments so you can see what is going on...

function acf_json_absolute_path ($path) {

    /**

    var_dump($path);

    Array (
        [0] => /sites/joshmoto/subdomains/domain.com/wp-content/themes/werks/acf-json
    )

    */

    $path[0] = get_template_directory() . '/config/acf-json';

    /**

    var_dump($path);

    Array (
        [0] => /sites/joshmoto/subdomains/domain.com/wp-content/themes/werks/config/acf-json
    )

    */

    return $path;
}

add_filter('acf/settings/save_json', 'acf_json_absolute_path');
add_filter('acf/settings/load_json', 'acf_json_absolute_path');


But every time I save my custom fields, nothing appears in the config/acf-json folder.

But if I create an empty acf-json folder in the root of my theme, and re-save all my ACF field groups, json files are created here instead.

enter image description here

I don't understand why config/acf-json path is getting ignored and using the default acf-json location?

Can anyone help me understand save/load json to my config folder location?

1

the two filters don't have the same output. you can test that

add_filter('acf/json_directory', function ($path) {
    return get_template_directory() . '/config/acf-json';
});


add_filter('acf/settings/save_json', function ($path) {

    return apply_filters("acf/json_directory", NULL);

});

add_filter('acf/settings/load_json', function ($paths) {

    return [
        apply_filters("acf/json_directory", NULL)
    ];

});
  • So the load_json is in and array the save_json is not. Perfect this works nicely thank you! – joshmoto Nov 19 '19 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.