Be Studios

Intercontinental Design Firm

This is our knowledge center. Enjoy!

WordPress: loop through each Taxonomy term

  $terms = get_terms('custom-post-type-name');
  foreach ($terms as $term) {
    $wpq = array ('taxonomy'=>'custom-post-type-name','term'=>$term->slug);
    $myquery = new WP_Query ($wpq);
    $article_count = $myquery->post_count;
    echo "<h3 class="term-heading" id="".$term->slug."">";
    echo $term->name;
    echo "</h3>";
    if ($article_count) {
     echo "<ul>";
     while ($myquery->have_posts()) : $myquery->the_post();
      echo "<li><a href="".get_permalink()."">".$post->post_title."</a></li>";
     endwhile;
     echo "</ul>";
    }
  }

source