Updated code
Source Link

#To get custom post type posts with specific category use custom taxonomy Register the taxonomy name of the custom post type like locationcategories and then assign locationa category to each post when you added new post. Here is the example of the code

  add_action( 'init', 'news_my_taxonomy');
  function news_my_taxonomy(){
 // custom post type taxonomies
    $labels = array(
    'name' => 'Categories',
    'singular_name' => 'Category',
    'add_new' => 'Add Category',
    'add_new_item' => 'Add New Category',
    'all_items' => 'All Categories',
    'edit_item' => 'Edit Item',
    'new_item' => 'New Item',
    'view_item' => 'View Item',
    'update_item' => 'Update Category',
    'search_items' => 'Search Categories',
    'not_found' => 'No record found',
    'not_found_in_trash' => 'No items found in trash',
    'parent_item_colon' => 'Parent Item',
    'menu_name' => 'Categories'
    );
    $args = array(
        'labels' => $labels,
        'hierarchical' => true,
        'has_archive' => true,
        'rewrite' => array('slug' => 'news_category'),
        'show_ui' => true,
        'show_admin_column' => true,
        'query_var' => true,
        );
        register_taxonomy('news_category', array('news'), $args);
}

#then #create taxonomy template page 'taxonomy-news_category.php' and add the query to get the posts with this category name

   $cat_name = single_cat_title;
   $args = array( 'category_name' => $cat_name, 'posts_per_page' => 12, 'order'=> 'ASC', 'post_type' => 'news', 'paged' => $paged);

All the work is done.Good luck

#To get custom post type posts with specific category use custom taxonomy Register the taxonomy name of the custom post type like location and then assign location to each post when you added new post. Here is the example of the code

  add_action( 'init', 'news_my_taxonomy');
  function news_my_taxonomy(){
 // custom post type taxonomies
    $labels = array(
    'name' => 'Categories',
    'singular_name' => 'Category',
    'add_new' => 'Add Category',
    'add_new_item' => 'Add New Category',
    'all_items' => 'All Categories',
    'edit_item' => 'Edit Item',
    'new_item' => 'New Item',
    'view_item' => 'View Item',
    'update_item' => 'Update Category',
    'search_items' => 'Search Categories',
    'not_found' => 'No record found',
    'not_found_in_trash' => 'No items found in trash',
    'parent_item_colon' => 'Parent Item',
    'menu_name' => 'Categories'
    );
    $args = array(
        'labels' => $labels,
        'hierarchical' => true,
        'has_archive' => true,
        'rewrite' => array('slug' => 'news_category'),
        'show_ui' => true,
        'show_admin_column' => true,
        'query_var' => true,
        );
        register_taxonomy('news_category', array('news'), $args);
}

#then #create taxonomy template page 'taxonomy-news_category.php' and add the query to get the posts with this category name

   $cat_name = single_cat_title;
   $args = array( 'category_name' => $cat_name, 'posts_per_page' => 12, 'order'=> 'ASC', 'post_type' => 'news', 'paged' => $paged);

All the work is done.Good luck

#To get custom post type posts with specific category use custom taxonomy Register the taxonomy name of the custom post type like categories and then assign a category to each post when you added new post. Here is the example of the code

  add_action( 'init', 'news_my_taxonomy');
  function news_my_taxonomy(){
 // custom post type taxonomies
    $labels = array(
    'name' => 'Categories',
    'singular_name' => 'Category',
    'add_new' => 'Add Category',
    'add_new_item' => 'Add New Category',
    'all_items' => 'All Categories',
    'edit_item' => 'Edit Item',
    'new_item' => 'New Item',
    'view_item' => 'View Item',
    'update_item' => 'Update Category',
    'search_items' => 'Search Categories',
    'not_found' => 'No record found',
    'not_found_in_trash' => 'No items found in trash',
    'parent_item_colon' => 'Parent Item',
    'menu_name' => 'Categories'
    );
    $args = array(
        'labels' => $labels,
        'hierarchical' => true,
        'has_archive' => true,
        'rewrite' => array('slug' => 'news_category'),
        'show_ui' => true,
        'show_admin_column' => true,
        'query_var' => true,
        );
        register_taxonomy('news_category', array('news'), $args);
}

#then #create taxonomy template page 'taxonomy-news_category.php' and add the query to get the posts with this category name

   $cat_name = single_cat_title;
   $args = array( 'category_name' => $cat_name, 'posts_per_page' => 12, 'order'=> 'ASC', 'post_type' => 'news', 'paged' => $paged);

All the work is done.Good luck

improved
Source Link

As I understand you want to#To get all posts of your taxonomy related to your custom post type. So If it is then just create a posts with specific category use custom taxonomy template like this "template-your_taxonomy_name.php". Replace the your_taxonomy_name to Register the taxonomy name of yourthe custom post type like location and then assign location to each post when you added new post.Now, query in taxonomy template Here is the example of the code

    <?php 
        $c_cat = get_the_termsadd_action($post->ID 'init', 'your-taxonomy-name''news_my_taxonomy');
        function foreachnews_my_taxonomy($c_cat as $cat){
        // custom post type taxonomies
    $args$labels = array(
                             'posts_per_page''name' => -1'Categories',
                             'orderby''singular_name' => 'date''Category',
                             'order''add_new' => 'ASC''Add Category',
              'add_new_item' => 'Add New Category',
    'all_items' => 'All Categories',
    'post_type''edit_item' => 'custom-post-type-name''Edit Item',
        'new_item' => 'New Item',
    'view_item' => 'View Item',
    'update_item' => 'Update Category',
    'doctor-department''search_items' => $cat->name'Search Categories',
    'not_found' => 'No record found',
    'not_found_in_trash' => 'No items found in trash',
    'parent_item_colon' => 'Parent Item',
    'post_status''menu_name' => 'publish''Categories'
                         );
                         $postslist$args = get_postsarray( $args );
             'labels' => $labels,
        'hierarchical' => //print_r($postslist);true,
             'has_archive' => true,
        'rewrite' => foreacharray($postslist'slug' as=> $post'news_category'){,
                      'show_ui' => ?>true,
                                <div class="col-sm-12 col-md-6'show_admin_column' col-lg-6=> card-bg-small">true,
                                    <div class="col-sm-12 col-md-3 col-lg-3"><div class="round_icon" style="padding-top:15px;"><i class="fa fa-user-md'query_var' fa-3x"=> aria-hidden="true"></i></div></div>true,
                                    <div class="col-sm-12 col-md-9 col-lg-9 card-content"><h4 class="heading_nop"><?php the_title(); ?></h4>
                                            <a href="<?phpregister_taxonomy('news_category', the_permalinkarray('news'); ?>" class="btn btn-read_more">Read More</a>
                                    </div>
                                </div>
                               , <?php$args);
                                }
                   

#then #create taxonomy template page 'taxonomy-news_category.php' and add the query to get the posts with this category name

   $cat_name = }single_cat_title;
        $args = array( 'category_name' => $cat_name, 'posts_per_page' => 12, 'order'=> 'ASC', 'post_type' => 'news', 'paged' => ?>$paged);

All the work is done.Good luck

As I understand you want to get all posts of your taxonomy related to your custom post type. So If it is then just create a taxonomy template like this "template-your_taxonomy_name.php". Replace the your_taxonomy_name to the taxonomy name of your custom post type.Now, query in taxonomy template

    <?php 
        $c_cat = get_the_terms($post->ID, 'your-taxonomy-name');
         foreach($c_cat as $cat){
                $args = array(
                             'posts_per_page' => -1,
                             'orderby' => 'date',
                             'order' => 'ASC',
                             'post_type' => 'custom-post-type-name',
                             'doctor-department' => $cat->name,
                             'post_status' => 'publish'
                         );
                         $postslist = get_posts( $args );
                         //print_r($postslist);
                         foreach($postslist as $post){
                        ?>
                                <div class="col-sm-12 col-md-6 col-lg-6 card-bg-small">
                                    <div class="col-sm-12 col-md-3 col-lg-3"><div class="round_icon" style="padding-top:15px;"><i class="fa fa-user-md fa-3x" aria-hidden="true"></i></div></div>
                                    <div class="col-sm-12 col-md-9 col-lg-9 card-content"><h4 class="heading_nop"><?php the_title(); ?></h4>
                                            <a href="<?php the_permalink(); ?>" class="btn btn-read_more">Read More</a>
                                    </div>
                                </div>
                                <?php
                                }
                        }
                        ?>

#To get custom post type posts with specific category use custom taxonomy Register the taxonomy name of the custom post type like location and then assign location to each post when you added new post. Here is the example of the code

  add_action( 'init', 'news_my_taxonomy');
  function news_my_taxonomy(){
 // custom post type taxonomies
    $labels = array(
    'name' => 'Categories',
    'singular_name' => 'Category',
    'add_new' => 'Add Category',
    'add_new_item' => 'Add New Category',
    'all_items' => 'All Categories',
    'edit_item' => 'Edit Item',
    'new_item' => 'New Item',
    'view_item' => 'View Item',
    'update_item' => 'Update Category',
    'search_items' => 'Search Categories',
    'not_found' => 'No record found',
    'not_found_in_trash' => 'No items found in trash',
    'parent_item_colon' => 'Parent Item',
    'menu_name' => 'Categories'
    );
    $args = array(
        'labels' => $labels,
        'hierarchical' => true,
        'has_archive' => true,
        'rewrite' => array('slug' => 'news_category'),
        'show_ui' => true,
        'show_admin_column' => true,
        'query_var' => true,
        );
        register_taxonomy('news_category', array('news'), $args);
}

#then #create taxonomy template page 'taxonomy-news_category.php' and add the query to get the posts with this category name

   $cat_name = single_cat_title;
   $args = array( 'category_name' => $cat_name, 'posts_per_page' => 12, 'order'=> 'ASC', 'post_type' => 'news', 'paged' => $paged);

All the work is done.Good luck

improved
Source Link
    <?php 
        $c_cat = get_the_terms($post->ID, 'doctor'your-department'taxonomy-name');
         foreach($c_cat as $cat){
                $args = array(
                             'posts_per_page' => -1,
                             'orderby' => 'date',
                             'order' => 'ASC',
                             'post_type' => 'my'custom-doctor'post-type-name',
                             'doctor-department' => $cat->name,
                             'post_status' => 'publish'
                         );
                         $postslist = get_posts( $args );
                         //print_r($postslist);
                         foreach($postslist as $post){
                        ?>
                                <div class="col-sm-12 col-md-6 col-lg-6 card-bg-small">
                                    <div class="col-sm-12 col-md-3 col-lg-3"><div class="round_icon" style="padding-top:15px;"><i class="fa fa-user-md fa-3x" aria-hidden="true"></i></div></div>
                                    <div class="col-sm-12 col-md-9 col-lg-9 card-content"><h4 class="heading_nop"><?php the_title(); ?></h4>
                                            <a href="<?php the_permalink(); ?>" class="btn btn-read_more">Read More</a>
                                    </div>
                                </div>
                                <?php
                                }
                        }
                        ?>
    <?php 
        $c_cat = get_the_terms($post->ID, 'doctor-department');
         foreach($c_cat as $cat){
                $args = array(
                             'posts_per_page' => -1,
                             'orderby' => 'date',
                             'order' => 'ASC',
                             'post_type' => 'my-doctor',
                             'doctor-department' => $cat->name,
                             'post_status' => 'publish'
                         );
                         $postslist = get_posts( $args );
                         //print_r($postslist);
                         foreach($postslist as $post){
                        ?>
                                <div class="col-sm-12 col-md-6 col-lg-6 card-bg-small">
                                    <div class="col-sm-12 col-md-3 col-lg-3"><div class="round_icon" style="padding-top:15px;"><i class="fa fa-user-md fa-3x" aria-hidden="true"></i></div></div>
                                    <div class="col-sm-12 col-md-9 col-lg-9 card-content"><h4 class="heading_nop"><?php the_title(); ?></h4>
                                            <a href="<?php the_permalink(); ?>" class="btn btn-read_more">Read More</a>
                                    </div>
                                </div>
                                <?php
                                }
                        }
                        ?>
    <?php 
        $c_cat = get_the_terms($post->ID, 'your-taxonomy-name');
         foreach($c_cat as $cat){
                $args = array(
                             'posts_per_page' => -1,
                             'orderby' => 'date',
                             'order' => 'ASC',
                             'post_type' => 'custom-post-type-name',
                             'doctor-department' => $cat->name,
                             'post_status' => 'publish'
                         );
                         $postslist = get_posts( $args );
                         //print_r($postslist);
                         foreach($postslist as $post){
                        ?>
                                <div class="col-sm-12 col-md-6 col-lg-6 card-bg-small">
                                    <div class="col-sm-12 col-md-3 col-lg-3"><div class="round_icon" style="padding-top:15px;"><i class="fa fa-user-md fa-3x" aria-hidden="true"></i></div></div>
                                    <div class="col-sm-12 col-md-9 col-lg-9 card-content"><h4 class="heading_nop"><?php the_title(); ?></h4>
                                            <a href="<?php the_permalink(); ?>" class="btn btn-read_more">Read More</a>
                                    </div>
                                </div>
                                <?php
                                }
                        }
                        ?>
Source Link
Loading