Last active
July 25, 2017 07:33
-
-
Save gamaup/b33e06ff56ebc019ecf96e2d8fac2774 to your computer and use it in GitHub Desktop.
Get nearby location based on lat-long set on postmeta.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set @latitude = xxx; — center latitude | |
set @longitude = xxx; — center longitude | |
set @distance = xx; — search distance (miles) | |
select p.ID, p.post_name, ((ACOS(SIN(@latitude * PI() / 180) * SIN('latitude.meta_value' * PI() / 180) + COS(@latitude * PI() / 180) * COS('latitude.meta_value' * PI() / 180) * COS((@longitude – 'longitude.meta_value') * PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS distance | |
from wp_posts p | |
left join wp_postmeta latitude on latitude.post_id = p.ID and latitude.meta_key = '_latitude' | |
left join wp_postmeta longitude on longitude.post_id = p.ID and longitude.meta_key = '_longitude' | |
having distance < @distance; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment