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 –