更新1
正如@Florian指出的,我们不需要使用wp\\u list\\u pulk函数,只需添加
\'fields\' => \'ids\'
到WP\\U查询以检索ID列表:
$producers = new WP_Query(
array(
\'fields\' => \'ids\',
\'post_type\' => \'producers\',
\'posts_per_page\' => -1,
\'tax_query\' => array(
array(
\'taxonomy\' => \'region\',
\'field\' => \'slug\',
\'terms\' => \'alsace\'
)
)
)
);
然后通过替换$producerIds来检索葡萄酒
by
$制片人->帖子`。
解决方案
首先,我必须从该地区取回生产商:
$producers = new WP_Query(
array(
\'post_type\' => \'producers\',
\'posts_per_page\' => -1,
\'tax_query\' => array(
array(
\'taxonomy\' => \'region\',
\'field\' => \'slug\',
\'terms\' => \'alsace\'
)
)
)
);
然后使用
wp_list_pluck:
$producerIds = wp_list_pluck($producers->posts, \'ID\');
最后,我用生产者的ID检索葡萄酒:
$wines = new WP_Query(
array(
\'post_type\' => \'wines\',
\'posts_per_page\' => 12,
\'tax_query\' => array(
array(
\'taxonomy\' => \'type\',
\'field\' => \'slug\',
\'terms\' => \'white\'
)
),
\'meta_query\' => array(
array(
\'key\' => \'producer\',
\'value\' => $producerIds,
\'compare\' => \'IN\'
)
)
)
);