我有两种自定义帖子类型:“服务”和“作品”,它们都有相同的分类法“流派”。现在分类法“流派”有一个术语叫做“新手”。5最近在“作品”下发布的带有“新手”一词的帖子(在分类法“流派”下)必须在带有“新手”一词的“服务”的帖子页面上查询(在分类法“流派”下)。分类法下将有50个术语。
查询与帖子本身具有相同分类的自定义帖子
1 个回复
SO网友:Rutwick Gangurde
假设你想要它作为“流派”分类法中的所有术语。在single Service post页面的循环中,输入以下代码:
<?php
$the_terms = get_the_terms( get_the_ID, \'genre\' );
if(isset($the_terms) && !empty($the_terms)){
foreach($the_terms as $the_term){
$the_terms_slugs[] = $the_term->slug;
}
}
$works = get_posts(array(
\'post_type\' => \'works\',
\'posts_per_page\' => 5,
\'tax_query\' => array(array(
\'taxonomy\' => \'genre\',
\'field\' => \'slug\',
\'terms\' => $the_terms_slugs
)));
//This will print the works which have the same genre as the current post
print_r($works_query);
?>
如果您只想让它成为“新手”,请告诉我,我会修改代码。结束