好吧,我想我已经解决了我自己的问题。在对我的问题的评论中,上面的链接最终证明是答案。简而言之,我可以将值数组传递给数据库查询字符串吗?不需要。但我可以创建一个连接字符串来创建如下查询:
$locIDS = join(\',\',$loc_array);
代码如下所示:
wp_term_relationships.term_taxonomy_id IN ($locIDS)
它呈现如下:
wp_term_relationships.term_taxonomy_id IN (24,25,26,27,28,29,30,39,44,64,65,66,72)
下面是允许我处理此请求的最终代码:
$loc_array = array();
function get_local_ids($continent_id, $loc_arr){
global $wpdb;
$contQ = "SELECT wp_term_taxonomy.term_taxonomy_id FROM wp_term_taxonomy WHERE wp_term_taxonomy.parent = $continent_id AND wp_term_taxonomy.count > 0";
$locID = $wpdb->get_results($contQ, ARRAY_N);
foreach($locID as $locVal){
echo "The value of locVal is: ". $locVal[0] ."<br>";
$loc_arr[] = $locVal[0];
get_local_ids($locVal[0], $loc_arr);
}
return $loc_arr;
}
$loc_array = get_local_ids($contID, $loc_array);
var_dump($loc_array);
$locIDS = join(\',\',$loc_array);
$mQuery = "
SELECT $wpdb->posts.*
FROM $wpdb->posts, $wpdb->term_relationships
WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id
AND $wpdb->term_relationships.term_taxonomy_id IN ($locIDS)
AND $wpdb->posts.post_status = \'publish\'
AND $wpdb->posts.post_type = \'mineral\'
AND $wpdb->posts.post_date < NOW()
ORDER BY $wpdb->posts.ID DESC
";
实际上,我在实际的代码中得到了比这更多的东西。但我认为这解释了我是如何在我的问题中完成我想要做的事情的。