1

I have created a function on the main site in my multisite network that loops through each site in the network, pulls the values from their options page in ACF, and saves the data to a JSON file. However, I am unsure about how to get it to run outside of a single .php page that I've tested.

My questions are:

  • When is the best time to run this function?
  • Is the easiest method putting it in a custom plugin and giving it a button to click to run?
  • Is there any way I can automate the process, as ideally I would like it to run either when a new site is added to the network or the ACF options of an existing site change?

One issue I have is that my main site and subsites are on separate themes and don't share the same functions.php file, so I don't think using something like acf/save_post would work.

1

Create a plugin for the mu-plugins directory and have your function run when the wpmu_new_blog action fires.

Reference, here: https://codex.wordpress.org/Plugin_API/Action_Reference/wpmu_new_blog

The hook you cited for ACF seems to be the way you ought to run you function, if you want that to happen upon ACF save...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.