Recently I came across an amazing plugin named Advanced Custom Fields. This thing allows me to rapidly develop themes with clean, easy to use forms for custom fields. Those custom fields become the main content of front end layouts, much like my current About page.

This plugin has the ability to have a JSON file that has your field structure in it, and if you update that file, it will ask you if you want to sync those changes. Well, since I am going to hide the plugin, and I want to just push updates to my clients, I needed a way to automatically sync the updates.

I opened up the code for the plugin to see how the sync worked, took some of the code, and wrote my own function to perform the sync. Enter the gist of it:

I’ve tested it with one and two updated JSON files at the same time without any issues. You just need to be sure you understand what you’re doing with the Synchronized JSON ability of ACF.

4 thoughts on “Automatically update Advanced Custom Fields field groups via JSON

  1. Would love to discuss this sync with you some more. When i use it inside of my plugin, it just runs continuously without stopping. Any thoughts?

  2. It seems like there’s some unnecessary (or perhaps just unexplained) code here. For instance:
    what is the point of line 48?
    why do `$sync as $key => $v` if you’re never going to use $v?

  3. In that instance I needed the value of the `$key` to complete the process. If I recall correctly, the array was multidimensional, so flipping it wouldn’t have worked. I guess I could have used `array_keys` just to get the keys and then process those.

  4. Sorry this reply was so late, but no, I am not sure what can be happening. At this point, I haven’t use this code in well over a year, so something may have changed on the ACF side of things.

Leave a Reply

Your email address will not be published. Required fields are marked *

seventy one − = sixty eight