Today I’ve written a short tutorial to show you how to leverage pods framework pre-save filter in order to automatically get address coordinates using Google geocoding functionalities.


As I stated in previous post – most of my tutorials code will be hosted on GitHub to allow me (and hopefully you too) to update all of the code snippets in more efficient manner. At the same time I would like to paste the code here too for all non-github users and not to force you to jump between sites. I will try to keep both versions the same but please head to my GitHub repository for the newest version of the snippet.

How to use it?

  1. Add two fields to your pod – one for the address and second one for automatically generated coordinates.
  2. Go to my GitHub repository or copy code from down below.
  3. Put the code into your theme’s functions.php file or to your custom UI plugin.
  4. Replace %%podname%%, %%address_field_name_here%%, %%coordinates_field_name_here%% with the proper values (your pod name, name of your address field, name of your coordinates field).
  5. And that should be it.

I have few address fields in my pod, what now?

If you keep address separated in your pod then you can still use the code with just slight modification:

Please remember about removing the if statement in such case (the one checking if the address field exists). Also it would be good to sanitize user input to be sure that our request url is nice and clean

Why there are two filters in the code?

If you take a closer look into the code you will see that I’ve used two filters in there. The first one is responsible for our core functionality and calls nice lady from Google to get coordinates from her ;). The second one is just small function which uses a little bit dirty code to make coordinates field disabled – so the user will not be able to modify the values.

Full filter code

Related posts

Posted by Kamil Grzegorczyk Owner / Development