最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ACF save json to custom directory not working, default acf-json used instead

programmeradmin1浏览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/wp-content/themes/werks/acf-json
    )

    */

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

    /**

    var_dump($path);

    Array (
        [0] => /sites/joshmoto/subdomains/domain/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.

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?

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/wp-content/themes/werks/acf-json
    )

    */

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

    /**

    var_dump($path);

    Array (
        [0] => /sites/joshmoto/subdomains/domain/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.

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?

Share Improve this question asked Nov 19, 2019 at 11:24 joshmotojoshmoto 4676 silver badges19 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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)
    ];

});
发布评论

评论列表(0)

  1. 暂无评论