title: How to display custom post category name list in wordpress
body: <p>I have two custom post types(gallery and activities) in my wordpress site. I want to display the categories in gallery post type. But my code is showing all the categories in both post types(gallery and activities). I'm using advanced custom fields(ACF) and CPT-UI to create custom posts. How can I display the categories only in gallery. here is my code.</p>
  
  <pre><code>&lt;?php $catargs = array(
   'post_type'              =&gt; 'gallery',
  
   'orderby'                  =&gt; 'name',
  
   'order'                    =&gt; 'ASC',
  
   ); 
  
   $categories = get_categories( $catargs );
  
   foreach ($categories as $category) {?&gt;
  &lt;h1 class="entry-title" style="padding-top:30px;"&gt;
  &lt;?php     echo  $category-&gt;name;// Category title ?&gt;&lt;/h1&gt;
  
  &lt;?php
  
  // WP_Query arguments
  
  $args = array (
  
      'post_type'              =&gt; 'gallery',
  
      'cat'                    =&gt; $category-&gt;cat_ID,
  
  
      'order'                  =&gt; 'ASC',
  
  'orderby'                =&gt; 'title',
  
  );
  
  
  
  // The Query
  
  $query = new WP_Query( $args );
  
  
  
  // The Loop
  
  if ( $query-&gt;have_posts() ) {
  
      while ( $query-&gt;have_posts() ) {
  
          $query-&gt;the_post();
  
          ?&gt;
   &lt;div class="col-md-4 col-sm-4 col-xs-12" id="all-post"&gt;
   &lt;?php $url = wp_get_attachment_url( get_post_thumbnail_id($query-&gt;ID) );     ?&gt;
   &lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;img src="&lt;?php echo $url ?&gt;" class="img-responsive thumb-image-cust thumbnail" alt=""&gt;&lt;/a&gt;
  
   &lt;/div&gt;
          &lt;?php 
  
          // You can all phone/ email here
  
      }
  
  } else {
  
      // no posts found
  
  }
  
  // Restore original Post Data
  
  wp_reset_postdata();
  
  }
   ?&gt;
  </code></pre>