title: List categories and their posts from custom post type
body: <p>I want to show the categories and their posts. (custom post type)</p>
  
  <p><strong>It should look like this:</strong></p>
  
  <p>Category 1</p>
  
  <ul>
  <li>Post A (has cat. 1)</li>
  <li>Post B (has cat. 1)</li>
  </ul>
  
  <p>Category 2</p>
  
  <ul>
  <li>Post X (has cat. 2)</li>
  <li>Post Y (has cat. 2)</li>
  </ul>
  
  <p><strong>At the moment I get following output:</strong></p>
  
  <p>Category 1</p>
  
  <ul>
  <li>Post A (in cat. 1)</li>
  <li>Post B (in cat. 1)</li>
  <li>Post X (in cat. 2)</li>
  <li>Post Y (in cat. 2)</li>
  </ul>
  
  <p>Category 2</p>
  
  <ul>
  <li>Post A (in cat. 1)</li>
  <li>Post B (in cat. 1)</li>
  <li>Post X (in cat. 2)</li>
  <li>Post Y (in cat. 2)</li>
  </ul>
  
  <p><strong>Heres my code: functions.php</strong></p>
  
  <pre><code>... 
  register_taxonomy(
      'aundo-cat',
      'cdh_aundo',
      array(
          'hierarchical' =&gt; true,
          'label' =&gt; 'Kategorien A und O',
          'query_var' =&gt; true,
          'rewrite' =&gt; true
          )
      );
  ...
  
  
  add_action( 'init', 'create_post_type' );
  function create_post_type() {
  register_post_type( 'cdh_aundo',
      array(
          'labels' =&gt; array(
              'name' =&gt; __( 'A und O' ),
              'singular_name' =&gt; __( 'A und O' )
              ),
          'public' =&gt; true,
          'has_archive' =&gt; false,
          'menu_icon' =&gt; 'dashicons-heart',
          'rewrite' =&gt; array ('slug' =&gt; 'a-und-o-der-unternehmenskommunikation'),
          'supports' =&gt; array (
              'title',
              'editor',
              'excerpt',
              'thumbnail',
              'category',
              'custom-fields',
              'revisions' )
          )
      );
  }
  </code></pre>
  
  <p><strong>Code in template file:</strong></p>
  
  <pre><code>&lt;?php
  $cat_args = array (
  'taxonomy' =&gt; 'aundo-cat',
  );
  $categories = get_categories ( $cat_args );
  
  foreach ( $categories as $category ) {
  $cat_query = null;
  $args = array (
      'order' =&gt; 'ASC',
      'orderby' =&gt; 'title',
      'posts_per_page' =&gt; -1,
      'post_type' =&gt; 'cdh_aundo',
      'taxonomy' =&gt; 'aundo-cat'
      );
  
  $cat_query = new WP_Query( $args );
  if ( $cat_query-&gt;have_posts() ) {
      echo "&lt;h3&gt;". $category-&gt;name ."&lt;/h3&gt;";
      echo "&lt;ul&gt;";
      while ( $cat_query-&gt;have_posts() ) {
          $cat_query-&gt;the_post();
          ?&gt;
          &lt;li&gt;
              &lt;a href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php the_title_attribute(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;
              &lt;?php if( get_field('aundo_tipp_nummer') ): ?&gt;
                  &lt;div class=""&gt;
                      &lt;?php the_excerpt(); ?&gt;
                  &lt;/div&gt;
              &lt;?php endif; ?&gt;
          &lt;/li&gt;
          &lt;?php
      }
      echo "&lt;/ul&gt;";
  }
  wp_reset_postdata();
  }
  ?&gt;
  </code></pre>