【发布时间】:2019-01-21 07:00:23
【问题描述】:
我在我的一个函数中使用了 WP_Query。
function get_id_list ($postType) {
$wpb_all_query = new WP_Query(
array(
'post_type' => $postType,
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_query' => array(
array(
//'key' => 'title',
//'value' => 'Wordpress Development BSP Project', // this works and the function only returns a list with the single ID of the post where this matches
'key' => 'bicslab_axis',
'value' => '22', // this does not work
'value' => 'greenware', // this does not work
)
)
)
);
$postIDList = [];
if($wpb_all_query->have_posts()){
while ( $wpb_all_query->have_posts() ) {
$wpb_all_query->the_post();
$postIDList[] = get_the_ID();
}
wp_reset_postdata();
}
print_r($postIDList);
return $postIDList;
}
当我在'meta_query' 中选择一个“文本”类型的字段时,查询可以正常工作,但如果我选择“关系”类型的字段,则不会。
对于我尝试输入 ID 和名称的关系字段,它们都不起作用。
如何使查询仅检索类型为关系的自定义字段仅与某些对象相关的帖子?
编辑:我应该澄清一下,我在我的 mea 查询中分别使用了 "22""greenware" 作为值,因为 22 是 ID,greenware 是具有该 ID 的特定博客文章/对象的“名称”
【问题讨论】:
标签: php wordpress advanced-custom-fields