Created
January 28, 2015 09:01
-
-
Save mihdan/a109a5b420e181df6c31 to your computer and use it in GitHub Desktop.
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 | |
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