如果只需要显示分配给分类法的帖子(仅显示分类法中每个术语的帖子列表,而不显示术语信息)
仅获取术语ID:
$custom_terms = get_terms( array(
\'taxonomy\' => \'how-to-guide-type\', //your taxonomy
\'hide_empty\' => true, //ignore terms without posts
\'fields\' => \'ids\' //return only terms ids
));
现在
$custom_terms 是一组术语ID。修改您的tax\\u查询,如下所示:
$query = new WP_Query([
\'post_type\' => \'cpt_how_to_guides\',
\'orderby\' => \'date\',
\'order\' => \'ASC\',
\'tax_query\' => [
[
\'taxonomy\' => \'how-to-guide-type\',
\'terms\' => $custom_terms, //array with terms ids of your taxonomy
\'operator\' => \'AND\' //display posts from all of these terms
],
],
]);
此外,您不需要为计数器创建自定义变量,您的$查询有一个用于此目的的属性。使用
$query->current_post 而不是
$counter 变量它从零开始。