我使用的是自定义帖子类型,在帖子中有一个复选框元字段featured post.
所以有两种情况。
当我用meta_query
其结果百分之百完美。
这是我的代码:
$c_clients_args = array(
\'post_type\' => \'clients_testimonials\',
\'posts_per_page\' => 6,
\'order\' => \'ASC\',
\'meta_query\' => array(
array(
\'key\' => \'c_client_feature\',
\'value\' => \'on\'
)
)
);
$c_clients_result = new WP_Query($c_clients_args);
if($c_clients_result->have_posts()) :
while($c_clients_result->have_posts()) :
$c_clients_result->the_post();
// My result
endwhile;
endif;
但当我用
meta_query
页面变为空白。
这是我的代码:
$c_client_args = array(
\'post_type\' => \'clients_testimonials\',
\'posts_per_page\' => 999,
\'order\' => \'ASC\',
\'meta_query\' => array(
array(
\'key\' => \'c_client_feature\',
\'value\' => \'on\',
\'compare\' => \'NOT LIKE\'
)
)
);
我也试过了
!=
和
NOT IN
所以请引导我。
SO网友:user5200704
尝试第二个查询
$c_client_args = array(
\'post_type\' => \'clients_testimonials\',
\'posts_per_page\' => 999,
\'order\' => \'ASC\',
\'meta_query\' => array(
\'relation\' => \'OR\',
array(
\'key\' => \'c_client_feature\',
\'compare\' => \'NOT EXISTS\'
),
array(
\'key\' => \'c_client_feature\',
\'value\' => \'on\',
\'compare\' => \'NOT IN\'
),
)
);