WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a custom post type for "locations" and I need to have "users" log in and be able to pick a location that is within a certain distance from them.

I have added some spots to the profile using update_contact_methods() to get an address etc, and the location custom post type I am using the Custom-Metaboxes-and-Fields-for-WordPress to add specific fields for address information etc.

I am simply not sure of how to achieve what I need to and am hoping for some input.

I need to get it working quickly so I am more concerned with at least a proof-of-concept approach then the most performant. My initial thought was to use Google Maps API distance matrix, https://developers.google.com/maps/documentation/javascript/distancematrix but I am not sure if that is a good way to go...

A thought was to have a page that is clickable once user is logged in, that would, upon navigating to it, would need to iterate through each "location" custom post and compare its address as destination and the logged in users address (pulled from profile) as origin, and discard the post if > (greater than) x hours. Does that make sense?

I would really appreciate any help you all may have to give, I have confused myself into a corner.

Thank you!

share|improve this question
Would be easier to help if you post your code please. – Brad Dalton May 4 '14 at 5:52
Are you looking for help integrating the post type meta data with the profile fields, or help with determining the distance from your location to your users? The integration, basically retrieving both variables from the database, is a WordPress question - how to determine the distances is a question better suited to StackOverflow and has been asked/answered at least here and here. – DACrosby May 10 '15 at 5:58

Several good links that might get you going:

If you use the Google Maps API to return a lat and long position, and store those in the database in a custom field, then you can use the Haversine formula to calculate distances and you won't need google maps for that anymore (google lookups make things slow). You might also store some meta info on the locations, so you can rule out groups of locations (countries, states, provinces etc).

The links have php excerpts you can use.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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