Is it viable and or advisable to try and implement a query like the below through get_terms and its meta query functionality? Basically, I query terms of a specific taxonomy 'pr' that have meta fields containing coordinates based on distance from a reference coordinate. My gut sense is that it will be more ellegant and efficient to keep the little pathagoras calaculation in the db query rather than having to loop through unnecessary results in php, perhaps I'm mistaken about that? Any pointers on what the structure of the meta querie(s?) should look like?
SET @refLat = -26.080;
SET @refLng = 28.015;
SELECT
term.term_id,
agt_Name.meta_value AS agt_Name,
metaLat.meta_value AS metaLat,
metaLng.meta_value AS metaLng,
(
SQRT(
POW( @refLat - metaLat.meta_value, 2 ) + POW( @refLng - metaLng.meta_value, 2 )
)
) * 111139 AS metresDistance
FROM
`wp_terms` term
INNER JOIN `wp_term_taxonomy` tax ON
( term.term_id = tax.term_id AND tax.taxonomy = 'pr' )
INNER JOIN `wp_termmeta` metaLat ON
( term.term_id = metaLat.term_id AND metaLat.meta_key = '_latitude' )
INNER JOIN `wp_termmeta` metaLng ON
( term.term_id = metaLng.term_id AND metaLng.meta_key = '_longitude' )
INNER JOIN `wp_termmeta` agt_Name ON
( term.term_id = agt_Name.term_id AND agt_Name.meta_key = 'agt_Name' )
ORDER BY
(
SQRT(
POW( @refLat - metaLat.meta_value, 2 ) + POW( @refLng - metaLng.meta_value, 2 )
)
) ASC
LIMIT 0,5
Thanks in advance.