high response time for a custom query
-
Hi
I use Job Manager plugin and I want to search for the locations that their distance are less than 10 Kilometers from input $lang and $lat. I use following query to do this, but it takes many time (more than 6 seconds) to respond. Do you know a better way or better sql query to do this?
$wpdb->prepare( " SELECT DISTINCT map_lat.post_id, p.post_title, map_lat.meta_value as locLat, map_lng.meta_value as locLong, ( 6371 * ACOS( COS(RADIANS( %s )) * COS(RADIANS(map_lat.meta_value)) * COS( RADIANS(map_lng.meta_value) - RADIANS( %s ) ) + SIN(RADIANS( %s )) * SIN(RADIANS(map_lat.meta_value)) ) ) AS distance FROM $wpdb->posts p INNER JOIN $wpdb->postmeta map_lat ON p.ID = map_lat.post_id INNER JOIN $wpdb->postmeta map_lng ON p.ID = map_lng.post_id WHERE 1 = 1 AND p.post_type = 'job_listing' AND p.post_status = 'publish' AND map_lat.meta_key = 'geolocation_lat' AND map_lng.meta_key = 'geolocation_long' HAVING distance < %s ORDER BY map_lat.post_id DESC LIMIT 5", $lat, $long, $lat, $radius );
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘high response time for a custom query’ is closed to new replies.