好的,我已经搜索了很多这个问题......我无法让它发挥作用......
我有用户注册X类,事实是同一个用户可以在两个类中注册,所以我使用ACF复选框将其添加到配置文件中,到目前为止一直很好
问题在于,当我进行查询以调出分配给该类的任务时,它会在单个值时出现错误但在有多个值时会中断...
元查询的数组返回此
Array ( [0] => Array ( [key] => p_class [value] => tc [compare] => LIKE ) [1] => Array ( [key] => p_class [value] => yb [compare] => LIKE ) [2] => Array ( [key] => p_class [value] => m1 [compare] => LIKE ) [3] => Array ( [key] => p_class [value] => m2 [compare] => LIKE ) [4] => Array ( [key] => p_class [value] => m3 [compare] => LIKE ) )
这是我用来创建查询的代码......
请帮助!!
if($_GET['uID']){
$uData = get_userdata( $_GET['uID'] );
}else{
$uData = wp_get_current_user();
}
$myClass = get_field('p_class', 'user_'.$uData->ID);
$meta_q = array();
foreach($myClass as $class){
$meta_q[] = array(
'key' => 'p_class',
'value' => $class,
'compare' => 'LIKE'
);
}
print_r($meta_q);
$args = array(
'post_type' => 'task',
'relation' => 'OR',
'meta_query' => $meta_q
);
$the_query = new WP_Query( $args );
答案 0 :(得分:0)
好吧..所以我终于找到了......希望这对任何人有帮助......
当你填写$ args数组时,你必须将[0]添加到$ meta_q数组......所以它看起来像这样......一切都很完美,除了这个:
$args = array(
'post_type' => 'task',
'relation' => 'OR',
'meta_query' => $meta_q[0]
);