Home › Forums › Backend Issues (wp-admin) › How to disable auto JSON sync for some field groups? › Reply To: How to disable auto JSON sync for some field groups?
The first thing you need to do is to add an acf-json folder to the child theme.
The second is to not unset the child them load point
// changes loading location for custom fields
add_filter('acf/settings/load_json', 'my_acf_json_load_point');
function my_acf_json_load_point( $paths ) {
// remove original path (optional)
// do not do this
//unset($paths[0]);
// append path
$paths[] = get_template_directory() . '/custom-fields';
// return
return $paths;
}
What will happen. JSON will be loaded from the child theme first, only field groups that do not exist in the child theme will be loaded by the parent theme.
Then you need to alter the save point code to only alter the save point for the fields you want to always load from the parent theme and not be overridden by the child theme. This takes 2 filters
The first filter adds the save point filter only to selected field groups when they are saved
add_action('acf/update_field_group', 'my_acf_json_update_field_group', 1, 1);
function my_acf_json_update_field_group($group) {
// list of field groups you want to save to parent theme
$groups = array(
'group_12345678',
'group_23456789',
// etc...
);
if (in_array($group['key'], $groups)) {
add_filter('acf/settings/save_json', 'my_acf_json_save_point', 9999);
}
return $group;
}
remove your other add_filter line
add_filter('acf/settings/save_json', 'my_acf_json_save_point');
and this will only affect the field groups specified in the first filter
function my_acf_json_save_point($path) {
// remove this filter so that it will not affect other field groups
remove_filter('acf/settings/save_json', 'my_acf_json_save_point', 9999);
// update path
$path = get_template_directory() . '/custom-fields';
// return
return $path;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.