Loading custom values into ACF field default values

A plugin I’m working on requires that the user be able to set the map center for a Google Map ACF field that is associated with a custom post type. Advanced Custom Fields has a good number of filters, but I wasn’t sure going in which filter I needed to use.  A quick Google lead me to this question on the ACF support forums which in turn led to this page on the ACF documentation.  From there it was as simple as plugging in my field names and values.

In the ACF JSON file for the options page, here is the field that allows the user to set the default map center:

Here is the JSON for the map field on the CPT:

And finally here is the code to put in the plugin constructor:

There are a few different filters you can hook onto depending on if you know the field key or if you want to set the values for all Google maps, but I chose to use this way since the field name is what we have the most control over.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.