ACF JSON Explained For Beginners

By default, ACF saves and loads all JSON files from the acf-json directory inside your theme, but it is possible to take control of ACF’s behaviour to define your custom load points as outlined in the Advanced Custom Fields documentation.

acf/settings/load_json

1. We’re using the acf/settings/load_json filter to add our custom path to the ACF JSON load path.

acf-add-index-php-file

2. We’re removing the original path (optional).

3. We’re adding our own custom path to the ACF JSON load path.

4. We’re returning the new ACF JSON load path.

Now, if you save your plugin and refresh the page, you should see the new field group appear in the Custom Fields menu.

acf-json sync not working

If you don’t see the new field group, make sure you’ve added the field group to the correct folder.

Code Snippet

add_filter('acf/settings/load_json', 'my_acf_json_load_point');

function my_acf_json_load_point( $paths ) {

    // remove original path (optional)
    unset($paths[0]);


    // append path
    $paths[] = plugin_dir_path( __FILE__ ) . 'acf-json';


    // return
    return $paths;

}

acf/settings/save_json

Each time you save a field group, a JSON file will be created (or updated) with the field group and field settings.

The JSON file will be named using the field group’s unique key.

Only one save point (folder) exists and can be customized by adding the following code to your theme

1. We’re adding a filter to the ACF settings.

2. We’re telling ACF to save the JSON files in a custom folder.

3. We’re telling ACF to save the JSON files in the child theme folder.

4. We’re telling ACF to save the JSON files in a folder called my-custom-folder.

5. We’re returning the path to the custom folder.

<?php
 
add_filter('acf/settings/save_json', 'my_acf_json_save_point');
 
function my_acf_json_save_point( $path ) {
    
    // update path
    $path = get_stylesheet_directory() . '/my-custom-folder';
    
    
    // return
    return $path;
    
}
 
?>

JSON Example

{
    "key": "group_review_card",
    "title": "Review Card",
    "fields": [
        {
            "key": "field_review_card_adam_take",
            "label": "Adam",
            "name": "adam",
            "type": "textarea",
            "instructions": "",
            "required": 0,
            "conditional_logic": 0,
            "wrapper": {
                "width": "",
                "class": "",
                "id": ""
            },
            "default_value": "",
            "placeholder": "",
            "maxlength": "",
            "rows": "",
            "new_lines": "",
            "acfe_textarea_code": 0,
            "acfe_field_group_condition": 0
        },
        {
            "key": "field_review_card_best_for",
            "label": "Best For",
            "name": "best_for",
            "type": "text",
            "instructions": "",
            "required": 0,
            "conditional_logic": 0,
            "wrapper": {
                "width": "",
                "class": "",
                "id": ""
            },
            "default_value": "",
            "placeholder": "",
            "prepend": "",
            "append": "",
            "maxlength": "",
            "acfe_field_group_condition": 0
        },
        {
            "key": "field_review_card_price",
            "label": "Price",
            "name": "price",
            "type": "text",
            "instructions": "",
            "required": 0,
            "conditional_logic": 0,
            "wrapper": {
                "width": "",
                "class": "",
                "id": ""
            },
            "default_value": "",
            "placeholder": "",
            "prepend": "",
            "append": "",
            "maxlength": "",
            "acfe_field_group_condition": 0
        },
        {
            "key": "field_review_card_annual_discount",
            "label": "Annual Discount",
            "name": "annual_discount",
            "type": "text",
            "instructions": "",
            "required": 0,
            "conditional_logic": 0,
            "wrapper": {
                "width": "",
                "class": "",
                "id": ""
            },
            "default_value": "",
            "placeholder": "",
            "prepend": "",
            "append": "",
            "maxlength": "",
            "acfe_field_group_condition": 0
        },
        {
            "key": "field_review_card_promotion",
            "label": "Promotion",
            "name": "promotion",
            "type": "text",
            "instructions": "",
            "required": 0,
            "conditional_logic": 0,
            "wrapper": {
                "width": "",
                "class": "",
                "id": ""
            },
            "default_value": "",
            "placeholder": "",
            "prepend": "",
            "append": "",
            "maxlength": "",
            "acfe_field_group_condition": 0
        },
        {
            "key": "field_review_card_score",
            "label": "Score",
            "name": "score",
            "type": "number",
            "instructions": "",
            "required": 0,
            "conditional_logic": 0,
            "wrapper": {
                "width": "",
                "class": "",
                "id": ""
            },
            "default_value": "",
            "placeholder": "",
            "prepend": "",
            "append": "",
            "min": 0,
            "max": 10,
            "step": "",
            "acfe_field_group_condition": 0
        }
    ],
    "location": [
        [
            {
                "param": "post_type",
                "operator": "==",
                "value": "post"
            }
        ]
    ],
    "menu_order": 0,
    "position": "normal",
    "style": "default",
    "label_placement": "left",
    "instruction_placement": "label",
    "hide_on_screen": "",
    "active": true,
    "description": "",
    "show_in_rest": 0,
    "acfe_autosync": [
        "json"
    ],
    "acfe_form": 0,
    "acfe_display_title": "",
    "acfe_meta": "",
    "acfe_note": "",
    "acfcdt_manage_table_definition": 1,
    "acfcdt_table_name": "review_rating_card",
    "acfcdt_table_definition_file_name": "table_review_rating_card"
}

Added Security

If you wish to hide your field group or field settings from the public, simply add an empty index.php file to your acf-json folder. WP uses the same method to hide the wp-content/themes folder.

<?php
// Silence is golden.
?>