Home › Forums › General Issues › Sync deleted fields with JSON?
Hello.
I deleted some fields on my development environment and pushed to my production where I synced. I expected the fields that I deleted to be removed but they where not – is this expected behaviour? If it is – what is the best way to set up a workflow where I can have a single source of truth for my fields, preferably created in my development environment and pushed to production?
Hi Johan,
To be sure, do you have an acf-json folder in your theme?
If it’s the case, are you sure that the json files in this folder are the same in your dev and prod environment?
Normally, if the json file is deleted in this folder, it’s also deleted in the back-office, even without sync.
Let me know.
I just did a test with some basic fields and the fields I deleted in the JSON file where deleted when I did the sync.
Are these more complex fields? Sub fields of a repeater or flex field or something like that?
Hi,
I did a check and the json files in the acf-json directory is the same on development and production (after syncing) – however the fields that where deleted still show up in my production environment. How can that be, do they come from the database then?
In this case, it’s a field group of two repeater fields (and nested text and image fields) and a plain text field.
Sure, i *can* do the same change on production, and delete it there – but that kind of defeats the purpose of this feature I think. The point is to have one source of truth, that changes I make in my development environment will be reflected in production. Modifying my fields in more places than one seems to be a recipe for disaster.
I’ve already seen this kind of issue when someone edit the field group in the prod environment then save it. If in the json file, the modified field differs, it can prevent the update to be done.
Can you try to test with another field:
Maybe you just have the issue with that particular field.
You can also have a look at your json files and be sure that the field group you excpected to be deleted is really not in the json folder.
I just did another test using repeaters, both deleting entire repeaters and deleting sub fields in repeaters. In all cases when I do the sync the fields I deleted from the JSON file are deleted from the field group.
Please provide the exact steps you are performing to push the change to the site.
Also, this conversation has become a little confusing. Are you trying to delete fields in a group or are you attempting to delete an entire field group?
Well, this was strange. I did the following for testing purpose:
OK so you really have an issue, it is not the expected behaviour.
Maybe you could delete all the fields in the prod environment, and try to re-sync all fields to see what happen?
Still confusing.
Are you trying to delete one field in a group?
Are you trying to delete an entire field group?
Hi, sorry maybe I’m unclear or not using the right terminology here.
What I am deleting is a “field group” (i guess, I have a my native language set). This field group contains one field, in my testcase, a simple textfield.
I add the group with the one text field and a new json file is created. I push to live and then I can sync and it shows up as it should.
However, if I on my local environent delete the group containing this text field, and push and pull, I get no changes to sync and the field is still there.
That explains a lot. ACF will not delete entire field groups if they are missing from the acf-json folder. What you are seeing is expected behavior. ACF will only save changes, load groups, and sync groups that exist in the folder.
I you want to automatically delete groups, I’m sure it would be possible, but you’d need to right custom code to detect the missing files and tell ACF to delete them. I don’t know of any examples of doing this or the code that would be involved, but basically you’d need to get a list of all the groups and see if there is a corresponding json file and if not then tell ACF to delete the group.
Ok – good to know that this is expected behaviour, thanks!
The fact that is doesn’t work like this makes me wonder though, am I wrong in thinking that this would be a good workflow? Is there a recommended workflow for keeping my development environment in sync with the changes I do on local?
Manually deleting the field groups in all environment’s doesn’t seem like a good way to keep everything “in sync”.
If I had to build something like this where I knew I would never edit or manage field groups on the production site I would build a function that would do the checking and deleting as I mentioned above.
Another option might be, instead of deleting groups to mark them as inactive so that they will not be used, this would allow syncing.
Generally, I never delete a field group once I’ve created it.
To be honest, if I had a production site that will only use active JSON files then the field groups of that site would never be stored in the database and the only place the field groups would exist would be in the acf-json folder. I would delete all of the field groups from ACF admin and upload the acf-json folder and just let ACF use the field groups from there. However, this will not work if you’re also syncing the DB in some way.
I’m not sure I’m following you. I never sync the database development > live, only the other way around. Would that be a problem with this approach?
How do I make sure the field groups are not loaded from the database but only from json on my production site? Should I delete the field groups on live and sync again?
Like I said above. Delete the groups from the database and then sync the files. This will mean the groups cannot be edited on the live site and will never be loaded from the database.
The topic ‘Sync deleted fields with JSON?’ 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!
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.