在wordpress中,我希望按经度和纬度获取帖子,但服务器在20-25秒内响应。
$querystr = "
SELECT
ACOS( SIN( RADIANS( $user_lat ) ) * SIN( RADIANS( pm1.meta_value ) ) + COS( RADIANS( $user_lat ) ) * COS( RADIANS( pm1.meta_value ) ) * COS( RADIANS( pm2.meta_value ) - RADIANS( $user_long ) ) ) *3959 AS distance,
pm1.meta_value AS lat, pm2.meta_value AS lon,
p.*
FROM wp_posts p
INNER JOIN wp_term_relationships ON ( p.id = wp_term_relationships.object_id )
INNER JOIN wp_postmeta pm1 ON p.id = pm1.post_id AND pm1.meta_key = 'latitude'
INNER JOIN wp_postmeta pm2 ON p.id = pm2.post_id AND pm2.meta_key = 'longitude'
WHERE post_type = 'post'
AND post_status = 'publish'
HAVING distance < 25
ORDER BY distance ASC
LIMIT 0 , 30
";
$results = $wpdb->get_results($querystr);