Home Forums General Issues Multisite Child Theme with same JSON file ID


Multisite Child Theme with same JSON file ID

  • I’ve inherited a multi-site where both parent and child theme are using acf-json folders. The child theme is using json files with the same filename and group id key as the parent.

    Presumably the developer expected that the child file would get used instead of the parent file as other template files do. Apparently when this site was launched it did work. Now there are problems.

    I’m not sure where to start to fix. I could remake this file but that would require me redoing all the data entry. They also don’t want the parent options to load in the child options.

    Looking for some guidance or suggestions. Thanks.

  • I’m wondering if this is the solution I am looking for. Only load some of the acf-json files from the parent.

  • There are many scenarios for using acf-json with parent/child themes, and this depends on whether or not they should be editable in the child them. Honestly, going into every use case would be impossible on this forum.

    However, once a field group is edited in a child theme then you cannot make any changes to that group in the parent them that will affect child theme sites where changes have been made. In most cases this is not going to be the desired use case since the purpose of having a parent theme is to be able to make changes that affect all sites using a child theme.

    If you are already at a point where changes have been made to sites using the child theme and you want to make changes to those groups in the parent them then you likely have a problem than cannot be resolved easily.

    You can force the child theme to use the parent theme json files using the code I posted in the other topic, but to do this you need to use array_unshift() to push the path to the beginning of the paths array so those groups are loaded first. Any groups that are loaded from one path will not override or modify groups with the same field key loaded from previous paths.

  • John, Thanks for your quick reply.

    In this case, the parent and child theme field groups do not require further or ongoing editing. I understand how a parent and child theme relationship should work. Like I said I inherited this project so trying to clean things up. I am also finding evidence that the original developer might not have understood how to load all field group properly as their calls to some group options create errors in php 8 when returning null values. Anyway…

    Currently the child theme and the parent theme share two files with the same group key. And what happens is that the parent theme json file gets used over the child file.

    Would you recommend I rebuild the child fields and just redo all the data entry? or is there another “easier” method. Like, can I recreate a unique group key in the child theme and move forward from there?

  • If the field groups in the parent and child theme are still the same, no edits were made in the child themes.

    1) Add the load point as you originally posted to load the groups from the parent theme.
    2) On the sites using the child theme delete the groups that should be loaded from the parent theme.
    3) Set the private argument in the parent acf json files to true

    Field groups from the parent theme will be loaded, they cannot be synced or edited in the child theme.

    You cannot “rebuilt” the groups. Building new groups the fields will have new field keys and all of the data will be lost…… unless you manually edit every post, term, user where they are used.

  • So I must not be explaining clearly. The child theme’s field group has been changed from the parent theme. The parent theme and the child theme each depend on their own fields in this group. The problem is this field group’s key id is the same in each json file.

    parent_theme/acf-json/group_5d28b22d3fdc0.json -> unique fields

    child_theme/acf-json/group_5d28b22d3fdc0.json -> unique fields

    The initial developer must have modified the fields in the child theme, which worked initially, but now only the parent theme fields are loading in the child theme.

    I’m trying to get the child theme field groups to work properly again. But I don’t know where to start because the field group keys are the same in the parent and child themes.

  • If that is the case then it is save to add the load point to with the code you referenced.

    What happens is this when the group key are duplicated.
    1) Field groups are loaded from the child theme
    2) Field groups are loaded from the parent theme, groups with duplicate keys are ignored

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

You must be logged in to reply to this topic.