I have something which puzzles me for a while reg. working with (git) branches.
Like any decent development company we work with git 😉
I have a branch named X, which is branched of the master branch.
I add fields to a certain group.
When I’m finished I commit my work.
It doesn’t get deployed/merged immediately because of code checks (by colleagues) etc.
If I then branch again from master, these fields are (still) in the database.
If I then add another field to the same group as where I’ve added something in the previous commit, these fields in the db also get saved to the JSON file.
How can we prevent this ?
Is it possible to ALWAYS read the JSON files and never from the database ? IMO that would be the solution since no other fields, get ‘loaded’ into the branch you’re working in.
If this is possible, I am not aware it is 🙂
This may not be for you. I have one site where there can be several changes going on at the same time by different developers. I also use git. To manage this I have multiple dev/staging/testing sites. A specific change is only done on one of these sites. In your case, each branch would equal another dev site, reusing dev sites for different purposes as branches are merged. There was a lot I needed to learn about .gitignore to accomplish this. Basically, in my case, the root of git is the root of the site and I ignore all of the WP files and anything else that will be updated through the normal update process while any file on the server that could might need changing is part of the repo. I needed to do this to include custom PHP files in folders off the root as well as include the theme and specific custom plugins for WP. It’s really complicated, but the only way I could figure out how to accomplish letting multiple devs work on different changes and only pushing specific changes to the live site.
I think that the only way you could do this would be to delete and re-import the field groups each time.
ACF does only read from the JSON if it exists, but not when editing a field group. In this case it only reads from the database. But ACF will write to the JSON files when you update including all fields that are in the database for the group. I don’t know that there is any way to prevent ACF from doing this or doing what you want.
1) Create Branch
2) Delete all of the field groups, maybe just the ones changed in some other branch)
3) Import the effected field groups, You can import them directly from the ACF JSON folder. Also, I think, but I’m not sure, that field groups that are in the acf-json folder but do not exist in the database may be available for sync.
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!
📣 “ACF Chat Fridays”— Advanced Custom Fields (@wp_acf) January 31, 2023
The ACF team holds their first open office hours this Friday! Come and talk ACF, and ask questions about building sites with the plugin.
We’d love to see you there!
📆 Friday 3rd Feb - 3pm UTC
👉 Register here - https://t.co/3UtvQbE4CU pic.twitter.com/oTwW9K1XQ0
© 2023 Advanced Custom Fields.