Hey @neoian - what you need is a 2 step process.
<循环类别/术语,然后在每个类别/术语内查询帖子。
$terms = get_terms("some_taxonomy");
$count = count($terms);
if ( $count > 0 ){
foreach ( $terms as $term ) {
$term_link = get_term_link( $term, \'some_taxonomy\' );
echo \'<h4 class="termTitle"><a href="\'.$term_link.\'">\' . $term->name . \'</a></h4>\';
$loop = new WP_Query( array(
\'post_type\' => \'some_postype\',
\'posts_per_page\' => 1000,
\'orderby\' => \'date\',
\'order\' => \'ASC\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'some_taxonomy\',
\'field\' => \'id\',
\'terms\' => $term->term_id
)
)
));
// the loop
echo \'<ul>\';
while ($loop->have_posts()) : $loop->the_post();
// get posts inside term
$postID = $loop->post->ID;
$postTitle = $loop->post->post_title;
echo \'<li><a href="\'.get_permalink().\'">\'.get_the_title().\'</a></li>\';
endwhile;
// reset $post so that the rest of the template is in the original context
wp_reset_postdata();
echo \'</ul>\';
}
}
remember to:将“some\\u taxonomy”更改为所需的分类,并将“some\\u postype”更改为您的自定义帖子类型。。。