Terrorpixel1991
4/4/2016 - 1:31 PM

Get All Categories Posts of Custom Post Types

Get All Categories Posts of Custom Post Types

<?php
    $cat_args = array (
      'taxonomy' => 'taxonomy-name',
    );
    $categories = get_categories ( $cat_args );
    foreach ( $categories as $category ) {
      $cat_query = null;
      $args = array (
        'post_type' => 'post-type-name',
        'taxonomy-name' => $category->slug
      );
      $cat_query = new WP_Query( $args );
      if ( $cat_query->have_posts() ) {
      echo "<h5>". $category->name ."</h5>";
      echo "<ul>";
        while ( $cat_query->have_posts() ) {
          $cat_query->the_post();
          ?>
            <li>
              <?php the_title(); ?>
              <?php the_content(); ?>
            </li>
          <?php
        }
      echo "</ul>";
      }
      wp_reset_postdata();
    }
?>