php – Display all categories (with link) of custom post type – WordPress


I have custom post type “case study”. Inside it i have few categories.
I want to display all existing categories from this “case study” CPT.

I successfully listed items from CPT on custom archive-case-study.php, using query:

$paged = get_query_var('paged')? get_query_var('paged') : 1;

$args = array(
    'post_type' => 'case_study',
    'post_status' => 'publish',
    'posts_per_page' => 6,
    'orderby' => 'date',
    'order' => 'DESC',
    'paged' => 1,

$wp_query = new WP_Query($args);

and loop:

<?php if ($wp_query->have_posts()):?>
    <div class="items">
      <?php while ($wp_query->have_posts()):?>
      <?php $wp_query->the_post();?>
        <a href="<?php echo get_permalink();?>" class="item">
          <h4 class="title"><?php the_title();?></h4>
      <?php endwhile;?>
<?php endif ;?>
<?php wp_reset_postdata(); ?>

Now im trying to create filters – list of all existing categories in this CPT “Case study” – i just want to list them above the “Case study” items.

(categories should be a links to new custom archives with list of items from clicked category still in “Case study” CPT)

I have tried many options but only what i had was empty response or errors…

What code in which place should i place? I will really appreciate the answer.

Thank you!

Tomasz W 1 year 2022-11-18T08:58:46-05:00 0 Answers 0 views 0

Leave an answer