List all posts in Custom Post Type but group dynamically by Custom Taxonomies

Try this piece of code for page template. I’ve used it on one of my projects. It outputs taxonomy term one by one with list of all posts with this term. (Just replace YOUR_TAXONOMY_SLUG to yours)

<div id="content">
<h2 class="entry-title"><?php the_title(); ?></h2>
    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    $mytaxonomy = get_terms('YOUR_TAXONOMY_SLUG', array("fields" => "names"));
    <?php for ( $myterm = 0; $myterm < count($mytaxonomy); $myterm++) { ?>
        <h3><?php echo $mytaxonomy[$myterm]; ?>:</h3>
        <ul class="taxonomy_group">
        <?php $loop = new WP_Query(array('YOUR_TAXONOMY_SLUG' => $mytaxonomy[$myterm]));
            while ( $loop->have_posts() ) : $loop->the_post(); ?>
                <li><a href="https://wordpress.stackexchange.com/questions/34496/<?php the_permalink(); ?>"><?php the_title();?></a></li>
            <?php endwhile; ?>  
        </ul>
    <?php } ?>
    </div><!-- #post-## -->
</div><!-- #content -->

Leave a Comment