0
我试图构建一个基于半径的位置搜索,以从我拥有的各种CPT返回相关的帖子。整个过程的工作原理,但我有一个问题,将一些参数传递给我的functions.php文件中的函数(我从窗体中获取它们,但不知道如何将它们传递给函数)。通过add_filter将参数传递给一个函数
参数是纬度和半径(目前手动写入我的functions.php中的代码)。
的search.php
的functions.php
function location_posts_where($where)
{
global $wpdb;
$lat = '41.834536';
$lng = '39.2440537479998';
$radius = 60;
$where .= " AND $wpdb->posts.ID IN (SELECT post_id FROM wp_lat_lng_post WHERE
(3959 * acos(cos(radians(" . $lat . "))
* cos(radians(lat))
* cos(radians(lng)
- radians(" . $lng . "))
+ sin(radians(" . $lat . "))
* sin(radians(lat)))) <= " . $radius . ")";
return $where;
}
不要使用过滤器,您可以使用$ wpdb自定义SQL查询并将所有代码保存在一个search.php文件中。 https://codex.wordpress.org/Class_Reference/wpdb –