Home › Forums › Bug Reports › Editor not loading local json of child-theme
Not sure if this is a bug since it’s using custom code but we’ve just discovered this issue while it was working before.
We’ve created a theme created with ACF to deploy for our customers. Now we’ve added this code so that when we roll out changes to the parent theme we can sync
the changes to the customer:
// Sync jsons with child
add_filter('acf/settings/load_json', 'parent_theme_field_groups');
function parent_theme_field_groups($paths) {
$path = get_template_directory().'/acf-json';
$paths[] = $path;
return $paths;
}
However with our newest customer we can’t make child-theme specific changes to the fields anymore. What happens is it creates a perfect json duplicate in the acf-json folder in the child theme. Also the fields editor shows the right data, however if we take a look at the fields in the editor it gives the field labels and data of the json in the parent theme.
If we remove the code mentioned above it shows us the right data from the child-theme. We didn’t have this issue with previous versions…
WP version: 6.0
ACF version: 5.12.2
The only thing I can think of here is that you have not created and acf-json folder in the child theme.
Sorry for coming back this late, we found a solution.
There seems to be an issue with the path acf takes to load the json. When you make changes in one of the jsons of the parent acf saves it in the child theme, as it should however it still reads the parent json.
// Integrating Advanced Custom Fields:
remove_filter('acf/settings/save_json', 'settings_save_json');
add_filter('acf/settings/save_json', function() {
return get_stylesheet_directory() . '/acf-json';
});
remove_filter('acf/settings/load_json', 'settings_load_json');
add_filter('acf/settings/load_json', function($paths) {
array_push(
$paths,
get_template_directory() . '/acf-json',
get_stylesheet_directory() . '/acf-json'
);
return $paths;
});
This seems to push the paths again.
You should not be removing any ‘acf/settings/load_json’ settings.
https://www.advancedcustomfields.com/resources/local-json/
You should only be adding paths. The stylesheet (child theme) path is added automatically by ACF. You would only remove this path if you don’t want the child theme to hold acf-json.
You must be logged in to reply to this topic.
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!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN
— Advanced Custom Fields (@wp_acf) March 2, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.