您的$advtxtQuery
查询--$where =" (( post_typs LIKE \'projects\')...
对于其余部分,两个查询都在同一个键上搜索,因此使用IN
而不是尝试创建两个单独的数组,如Codex example below:
$args = array(
\'post_type\' => \'my_custom_post_type\',
\'meta_key\' => \'age\',
\'orderby\' => \'meta_value_num\',
\'order\' => \'ASC\',
\'meta_query\' => array(
array(
\'key\' => \'age\',
\'value\' => array(3, 4),
\'compare\' => \'IN\',
)
)
);
$query = new WP_Query($args);
你可以把你的
$category
原来如此,但我会过滤它的恶意。事实上,您的值是(或似乎是)静态的,因此最安全的做法是:
$category_args = array();
if(!empty($category[0])) $category_args[] = "Planet";
if(!empty($category[1])) $category_args[] = "People";
并将其传递到查询中,如下所示:
if( !empty($category_args) ){
if(!isset($argsearch["meta_query"])){
$argsearch["meta_query"] = array();
}
$argsearch["meta_query"][] = array(
\'key\' => \'_cmb_project_category\',
\'value\' => $category_args,
\'compare\' => \'IN\'
);
}