ACF Migration

What is ACF Migration?

ACF Migration is the process which we push all the ACF field groups and its value between two different environments. For example: 

  • Push all the ACF field groups from your local website to staging website.
  • Push all the ACF field groups from your staging website to live website.

ACF Migration is a required process if you develop your website with ACF.

Standard ways

There are multiple ways to do this process. Here are some standard ways:

Manually

you will need to go to Admin -> Custom Fields -> Add New then add all the field groups you created in your development website to the website you want to migrate.

Advantages

  • Easy for the newbie.
  • Can do both initialize and update process.

Disadvantages

  • Taking a lot of time.
  • Easy to make mistakes, because we are both humans.

Export Json

This is a built-in feature of ACF. Go to Admin -> Custom Fields -> Tools in your development website, select your field groups which you want to export then click `Download export files`.

In the website you want to migrate, go to Admin -> Custom Fields -> Tools then import the json file which is downloaded before.


This is a popular way to migrate ACF field groups, and it is really good for the initializing process. But if you want to update ACF field groups by this way, you will need to trash the old field groups so I think it is not the good way for the updating process.

Advantages

  • Very fast.
  • Very good for the initializing process.

Disadvantages

  • It is not the good way for the updating process.

Using PHP Code

This is another built-in feature of ACF. Go to Admin -> Custom Fields -> Tools in your development website, select your field groups which you want to export then click `Generate export code`.

Copy this snippet to your theme’s functions.php file. If your website is using Sage 9 starter theme, copy this snippet to app/setup.php file.

Advantages

  • It is the developer-friendly way.
  • Very good for the initializing process.

Disadvantages

  • You can not update ACF field groups by this way.

Summary

All of these 3 ways do not let us update ACF field groups automatically, so it takes a lot of time to update field groups.

As a developer, we will need a programmatically way for the ACF Migration process. I will show you guys how to do this.

Programmatically way

After taking few hours to research, I found an awesome feature called Local Json(https://www.advancedcustomfields.com/resources/local-json/). This is a programmatically way to sync ACF field groups from our development website to the website we want to migrate. Here is the short description:

How?

Please follow these steps to integrate Local Json feature to your website:

  • Using acf/settings/save_json to update the endpoint which ACF will detect for saving field groups purpose.
    Copy this snippet into your theme’s functions.php file. If you are using Sage 9 starter theme, copy this snippet into app/setup.php(Note that the endpoint you defined will need to exist before):

  • Using `acf/settings/load_json` to update the endpoint ACF will detect for loading field groups purpose.
    Copy this snippet into your theme’s functions.php file. If you are using Sage 9 starter theme, copy this snippet into app/setup.php(Note that the endpoint you defined will need to exist before):

    Normally, both save endpoint and load endpoint will need to be the same endpoint.

  • Using git push/pull  or directly upload JSON file of the field groups to the site you want to migrate, note that the JSON file uploaded/pulled will need to be located inside the endpoint folder.
  • Go to Admin -> Custom Fields -> Field Groups -> Sync Available then click on Sync button to update the field groups:

Advantages

  • Very fast.
  • Developer-friendly.
  • Very good for both initializing process and updating process.

Disadvantages

In my point of view, there is no disadvantages when we use this method for ACF Migration process.

 

Conclusion: Local Json is an awesome programmatically way for ACF Migration process!

 

Slider: https://docs.google.com/presentation/d/1gqUXBDd8AS_rA_hPuLucDUV1cbraf_GQFxawI-apl4M/edit#slide=id.g32fe45f29c_0_155

Video: https://www.youtube.com/watch?v=Y3NbtxxKqAg

Reference: https://www.advancedcustomfields.com/resources/local-json/

 

You may also like...

Leave a Reply

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

%d bloggers like this: