Get all custom posts by taxonomy

$custom_terms = get_terms('your_custom_taxonomy');

foreach($custom_terms as $custom_term) {
    wp_reset_query();
    $args = array('post_type' => 'your_custom_post_type',
        'tax_query' => array(
            array(
                'taxonomy' => 'your_custom_taxonomy',                'field' => 'slug',
                'terms' => $custom_term->slug,
            ),
        ),
     );

     $loop = new WP_Query($args);
     if($loop->have_posts()) {
        echo '<h2>'.$custom_term->name.'</h2>';

        while($loop->have_posts()) : $loop->the_post();
            echo '<a href="'.get_permalink().'">'.get_the_title().'</a>';
        endwhile;
     }
}

Comments

Popular posts from this blog

Stop video playing when Bootstrap modal is closed