我正在尝试复制我构建的php mysql脚本,但要在Wordpress中工作。我使用mySQL编写的常规PHP脚本使用以下变量可以正常工作并返回结果:
$currLat = "43.653226";
$currLong = "-79.383184";
$blank = "";
$byDistance = "25";
$params = Array($currLat,$currLong,$currLat,$blank,$byDistance);
$sql = $appDb->rawQuery(\'SELECT *, ( 6371 * acos( cos( radians(?) ) * cos( radians( bLat ) ) * cos( radians( bLong ) - radians(?) ) + sin( radians(?) ) * sin( radians( bLat ) ) ) ) AS distance FROM business WHERE business.bLat != ? HAVING distance < ? ORDER BY distance\' , $params);
在Wordpress中创建带有参数的WP\\u查询时遇到问题?
$args = array(
\'post_type\' => \'el2business\',
// What else goes here to build the same query as my PHP mySQL Query Above
// I Have a meta box called bLat in my custom post type
// I have a meta box called bLong in my custom post type
);
这样我就可以跑去得到结果了?
$query = new WP_Query( $args );
if( $query->have_posts() ){
while( $query->have_posts() ){
$query->the_post();
$string .= \'<li>\' . get_the_title() . \'</li>\';
}
}
wp_reset_postdata();
return $string;