Support » Plugin: WP Store Locator » Get Post ID of Closest Store Location

  • I’ve got the Map, filters, and list all working properly on my site. What I’m looking for is to have a button in my header that, when clicked, displays some information for the closest store location to the user. Ultimately, what I need is to just get the post ID of the closest store location, I can manage the rest.

Viewing 1 replies (of 1 total)
  • Plugin Author Tijmen Smit


    How are you determining the users location?

    You could use a site like this to find the users location ( city level ) based on the users IP, but the IP is often from the ISP, and not the actual location so I don’t think it will be very accurate ( you can try to do this with JS as well )

    Once you have a location you can call the wpsl_call_geocode_api function to get the coordinates. With those coordinates you can make a search for nearby locations.

    You can see the function used for this here. You can copy the SQL query, and the relevant placeholder code and adjust it so it uses the coordinates returned from the freegeoip API ( there are lots of others offering the same service, but this is the only one I tested, so maybe others returned more accurate results based on the IP ).

    Place all the custom code in the functions.php inside your active theme folder, and then call the function to show the results in your template.

    I never tried it myself, but it should work, just not sure how accurate the IP location detection is.

Viewing 1 replies (of 1 total)
  • The topic ‘Get Post ID of Closest Store Location’ is closed to new replies.