I’ve got table in the WordPress database that has lat & lng stored and I’d like to add a sort feature on the results page ‘Sort by Distance’ that gets the locations that are closer to your provided lat & lng. I’m using WP_Query, it needs to work with it. Thanks 🙂
$my_query = new WP_Query( array(
'post_status' => 'publish',
'post_type' => 'post',
'category__in' => $category,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'age',
'field' => 'id',
'terms' => $age,
'operator' => 'IN'
),
array(
'taxonomy' => 'price',
'field' => 'id',
'terms' => $price,
'operator' => 'IN'
),
array(
'taxonomy' => 'group',
'field' => 'id',
'terms' => $group
)
),
'posts_per_page' => '-1',
) );
You want to use the Haversine formula
http://en.wikipedia.org/wiki/Haversine_formula
This plugin might be of interest to you:
http://wordpress.org/extend/plugins/wp-geoposts/
it uses the Haversine formula here:
http://plugins.svn.wordpress.org/wp-geoposts/trunk/query.php