【发布时间】:2017-03-14 22:24:00
【问题描述】:
所以我有这个功能来列出所有子页面,我希望它不列出那些没有自定义字段“角色”或者如果这个自定义字段为空的元素。我尝试了不同的方法,但即使我输入值或元值“测试”,所有页面都会列出。这个查询有问题,meta_key 工作正常,但 meta_value 不工作。
我的功能代码是这样的:
function list_child_pages() {
$args = array(
'numberposts' => -1,
'post_type' => 'page',
'meta_key' => 'role',
'meta_value' => 'test',
);
$the_query = new WP_Query( $args );
if ($the_query->have_posts()) {
return list_childs();
} else
$string="team members were not found";
return $string;
}
【问题讨论】:
-
在你的循环中怎么样,你可以 if(get_field('role')){ //echo your stuff here }
标签: wordpress advanced-custom-fields