I have below function to get nearby posts, and what I want to achevie is to get additional custom meta out of table "rate_review" how can I achieve it?
function get_nearby_locations2( $lat, $lng, $distance ) {
global $wpdb;
$earth_radius = 6371;
$sql = $wpdb->prepare( "
SELECT DISTINCT
map_lat.post_id,
p.post_title,
p.ID,
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 = 'beaches'
AND p.post_status = 'publish'
AND map_lat.meta_key = 'map_lat'
AND map_lng.meta_key = 'map_lng'
HAVING distance < '10'
ORDER BY distance ASC",
$lat,
$lng,
$lat
);
$nearbyLocations = $wpdb->get_results( $sql );
if ( $nearbyLocations ) {
return $nearbyLocations;
}
}
Which returns columns:
post_id
post_title
ID
locLat
locLong
distance