Support

Account

Home Forums Bug Reports Editor not loading local json of child-theme

Solving

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.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.