Update All ACF Post Fields

I use ACF (Advanced Custom Fields) in every site I build. Sometimes I need to transfer some posts from one site to another for various reasons. When you use the standard WordPress Export / Import of posts it does bring over the correct ACF values but the references to those values are not in place and so they are not available on the front end of the site (or anywhere on the site except in the post edit page itself). Usually there are WAY too many posts to go through and update them all one at a time. Here is a small function which will go through and update all of your ACF post fields at once so you do not need to manually update the posts.

You can call this function however you want. Usually it is done by using an action or something.

This function can run a long time so if you use this method make sure to comment out or remove the function / action after it runs.