$terms = get_terms('CUSTOM_TAXONOMY', ['hide_empty' => true]);
foreach( $terms as $term ){
echo '<section>';
echo '<h1>' . $term->name . '</h1>';
$posts = get_posts([
'post_type' => 'CUSTOM_POST_TYPE'
'tax_query' => [
[
'taxonomy' => 'CUSTOM_TAXONOMY',
'field' => 'term_id',
'terms' => $term->term_id
]
]
]);
echo '<ul>';
foreach($posts as $post){
echo sprintf('<li><a href="%s">%s</a></li>', get_permalink($post), $post->post_title);
}
echo '</ul>';
echo '</section>';
}