So far I’ve been using export php option and including that file in functions.php for my multisite so all instances can make use of the custom fields.
But since this does not actually create the custom field on the instances (except on the main one where I create them), this is causing some issues with other plugins such as Advanced Custom Search plugin that checks the field groups created on an instance to show its search fields.
My question is, how can I make sure the field groups are created on all multi site instances and they are all in sync with the main site?
What other things do I need to know and consider?
If all of the sites are using the same theme then you simply need to add the acf-json folder to the theme on the main site. If they are using different themes instead of using PHP you can add a JSON load point to the theme used on the main site. https://www.advancedcustomfields.com/resources/local-json/
@hube2 Yes, all sites use the same theme. From that local json page, it seems like I have to manually sync on each site? Is there a way to automate syncing?
From my use case, I have one template site where I make all the changes to the fields, once I save any changes, I want them to be automatically synced to all sites in my network.
No, you do not need to sync the files.
You edit a field group on the main site. The field group will never appear on the sub site to be edited and you would never edit them here. The existence of the group in the acf-json folder is all that is required, they will be loaded and used from there. If you are never going to edit the field groups on one of the sub sites then adding them to the database would be a waste of space. Using the same theme they will be already “synced”
Not sure that I follow. but this will only work if all of the sites use the same them and all of the same custom fields. If there are differences in the fields then you can’t really use this method.
Basically, what you need to have is one site that uses all of the fields that all of the other sites using the same theme will use where you edit the fields that will be used on those sites.
This is my setup:
Main site – different theme, different fields (used for admin purpose only)
All sub-sites – same theme, same fields (used by clients)
One of my sub-sites is called a “template” site where I make all pre-defined changes I want to replicate on all other sub-sites.
I am not doing anything on the main site for this. I am just using the template site where all the custom fields are created in the dashboard. I created acf-json folder in the theme folder which is shared by all other sites.
I made changes to all my field groups and I see a json file being created for each group. On all other sites, I see “Sync Available” tab in custom fields page. Is there a way to automatically sync it? That’s what I am asking.
You don’t need to sync them. The JSON files will be used everywhere except for editing them. If no one is going to edit these field groups on any of the other sites then syncing can be ignored.
If I was going to do something similar, this is what I would do, however, parts of the sites may not work during the process, so it really depends on how many of these sites you have.
STEP 0 – BACK UP YOUR DATABASE
1) I would go into all of the other sites (all of the sites except the main site where you plan on editing these field groups) and I would delete all of the field groups from ACF. This will also cause your JSON files to be deleted, meaning that the fields will not appear on these sites until you do step 2
2) Go back into the main site where you want to edit the groups and update each field group so that the JSON file is re-saved.
With that done you will have only one place where you can edit fields and those fields will be used on all sites using the same theme.
I did just that. I updated each field group on the main site where I edit the fields and I see all json files generated in the acf json folder. I went into each site and this is what I see:
There no custom fields defined in any of the other sites. They have not synced or registered with all other sites.
I never noticed it before, I guess when I’ve done this I’ve never looked at the ACF admin on the secondary sites because I never planned on editing fields there.
There is one way to solve this, but you’ll need to do it every time you edit a field group. You need to edit the JSON file. The end of the file will look something like this
"active": 1, "description": "" "modified": 1558547253
and you need to add a line
"active": 1, "description": "" "modified": 1558547253, "private": true
but like I said, you need to edit the file every time you update it on the main site
Interesting. It might be difficult to edit multiple JSON files everytime I make changes. What about PHP export file that will just be one file so its easier to edit. What can I add to it to make them show up in ACF admin on secondary sites?
I don’t plan to edit them either on the secondary sites (I have hidden that menu).
The whole reason to do this is to not edit them on the sub sites. All field groups added this way should be accessible to anything that needs them. The field groups exist the same as they would exist if loaded from the DB. The only difference is where they are loaded from. If there is some code that cannot access them you’d need to give me more details on this because that should not be the case. If other plugins cannot access the field it’s likely because they are not doing it properly.
If it is supposed to work with ACF I would contact them and ask why it’s not working with ACF local JSON feature. This feature was not available in ACF4 and ACF5 was just recently released as a free version. Maybe that’s the problem. I can’t say. But if this plugin needs to be used and you need to sync the fields on all sites then there isn’t an automatic way of doing this or causing ACF to do it.
Thanks John. I will contact them about it. This plugin hasn’t been updated since a year now. Maybe they have not added support for it.
For now I will use this instead – a modified version of the sync json acf plugin.
Only major down side of this is that it creates the fields in the database for each sub site which is what we are trying to avoid for performance reasons.
The topic ‘Multisite ACF’ is closed to new replies.
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!
© 2022 Advanced Custom Fields.