我正在努力让我的帖子按radius排序,到目前为止我一直在努力,我一直在使用Steve MArks的以下tut,http://biostall.com/performing-a-radial-search-with-wp_query-in-wordpress
下面是产生错误的代码,错误如下。
function location_posts_where( $where )
{
global $wpdb;
// Specify the co-ordinates that will form
// the centre of our search
$lat = \'50.12335\';
$lng = \'-1.344453\';
$radius = 10; // (in miles)
// Append our radius calculation to the WHERE
$where .= " AND $wpdb->posts.ID IN (SELECT post_id FROM 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 the updated WHERE part of the query
return $where;
}
调试日志中出现的错误是:
WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'IN (SELECT `post_id` FROM `lat_lng_post` WHERE ( 3959 * acos( cos( rad\' at line 1]
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = \'festival-event\' AND (wp_posts.post_status = \'publish\' OR wp_posts.post_status = \'private\') AND .ID IN (SELECT `post_id` FROM `lat_lng_post` WHERE ( 3959 * acos( cos( radians(50.12335) ) * cos( radians( \'lat\' ) ) * cos( radians( \'lng\' ) - radians(-1.344453) ) + sin( radians(50.12335) ) * sin( radians( \'lat\' ) ) ) ) <= 10) ORDER BY wp_posts.post_date DESC LIMIT 0, 10
在我看来,它无法连接到数据库。
我试着像前面的线程所说的那样,对字符串的db部分进行回溯,但这也不起作用。
我的SQL知识不高,但它在我的待办事项列表中,如果有任何帮助,我将不胜感激。