ACF Convert Old PHP fields to JSON

Back in the day, if you wanted to make sure you could keep your environments in sync (and you couldn’t just be moving the database around) you had to use PHP to build and update your ACF forms. It was gross.

Nowadays you can just work with the ACF fields in the admin like normal and ACF will AUTOMAGICALLY build a json form you can use to sync your different environments.

You do need to set this up a little bit, so stick this in your functions.php file to get started.

Now the tricker part is going to be converting your old PHP.

I just setup a script like the one below and ran it once. This script is taken fromĀ David Egan’s site.

All you need to do now is copy the output from this script into it’s own file (or you could just have PHP write that file for you) and save it as a .json.

IMPORTANT NOTE: At this point this json file probably wont work. I had to go through the file and double quote all of the keys and fix up some other formatting issues. This was 99% completed by just doing a single find and replace in Visual Studio Code. Regex: /”\s\w+:”/ This should find MOST of your keys and correctly format them so ACF can import them. This wont work PERFECTLY so you will need to scan your file to make sure everything is formatted right, but it will get you 99% of the way there.

Good Luck!