我正在尝试列出至少最近三个更新的自定义帖子类型的标题,让我们在另一个循环中称之为“Cast”,该循环是根据名为“actor”的分类术语列出的。我使用以下循环获得我的税务术语列表:
$taxonomy = \'actress\';
$term_args=array(
\'hide_empty\' => false,
\'orderby\' => \'name\',
\'order\' => \'ASC\'
);
$tax_terms = get_terms($taxonomy,$term_args);
?>
<ul>
<?php
foreach ($tax_terms as $tax_term) {
echo \'<li>\' . $tax_term->name.\'</li>\';
}
?>
</ul>
<?php
这有助于我列出术语,但我真的很困惑如何添加与自定义帖子相关的每个术语的列表?为了更清楚地说明以下图片,希望这能给你一个想法,我在寻找什么?你能帮我弄清楚怎么做吗?谢谢
Update
<?php
get_header();
//list terms in a given taxonomy
$taxonomy = \'actress\';
$term_args=array(
\'hide_empty\' => false,
\'orderby\' => \'name\',
\'order\' => \'ASC\'
);
$tax_terms = get_terms($taxonomy,$term_args);
?>
<ul>
<?php
foreach ($tax_terms as $tax_term) {
$loop = new WP_Query(
array(
\'post_type\' => \'cast\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'actress\',
\'field\'=>\'id\',
\'terms\' => $tax_term->ID
)
),
\'posts_per_page\' => 3
)
);
while ( $loop->have_posts() ) {
$loop->the_post();
echo \'<li>\' . get_the_title() . \'</li>\';
}
}
?>
</ul>
<?php get_footer(); ?>