我一直在试图找到一种在WP中进行radius搜索的方法,并决定采用一种比大型查询更简单的方法,但我在返回结果时遇到了问题
我有一个名为bar\\u get\\u nearear()的函数,它计算给定邮政编码的纬度/经度最大值/最小值,这样我就可以找到该最大值/最小值内的所有条目。
// GET POSTCODES LAT/LNG
$geo = file_get_contents(\'http://maps.googleapis.com/maps/api/geocode/json?address=\'.$_POST[\'location\'].\'&sensor=false\');
$decode = json_decode($geo);
$latlon = $decode->results[0]->geometry->location->lat.\',\'.$decode->results[0]->geometry->location->lng;
$dist = bar_get_nearby($decode->results[0]->geometry->location->lat, $decode->results[0]->geometry->location->lng);
// CHECK THEY WORK
echo $dist[\'max_latitude\'].\',\'.$dist[\'min_latitude\'].\'<--<br />\';
echo $dist[\'max_longitude\'].\',\'.$dist[\'min_longitude\'].\'<---<br />\';
// CREATE META QUERIES
$location_LAT = array(\'key\' => \'latitude\', \'value\' => $dist[\'max_latitude\'], \'compare\' => \'>=\');
$location_LAT2 = array(\'key\' => \'latitude\', \'value\' => $dist[\'min_latitude\'], \'compare\' => \'<=\');
$location_LNG = array(\'key\' => \'longitude\', \'value\' => $dist[\'max_longitude\'], \'compare\' => \'>=\');
$location_LNG2 = array(\'key\' => \'longitude\', \'value\' => $dist[\'min_longitude\'], \'compare\' => \'<=\');
我也试过了
$latitude = array(\'key\' => \'latitude\', \'value\' => array($dist[\'max_latitude\'],$dist[\'min_latitude\']), \'compare\' => \'BETWEEN\');
$longitude = array(\'key\' => \'longitude\', \'value\' => array($dist[\'max_longitude\'],$dist[\'min_longitude\']), \'compare\' => \'BETWEEN\');
没有错误,也没有返回结果,当我通过PHPMyAdmin运行查询时,我确实得到了结果。
然后,根据上述参数运行查询;
$args = array(\'post_type\' => \'choirs\', \'order\' => \'asc\', \'orderby\' => \'title\', \'posts_per_page\' => 500,
\'meta_query\' => array(
$location_LAT,
$location_LAT2,
$location_LNG,
$location_LNG2
));
query_posts($args);
任何帮助都将不胜感激谢谢,P