I have a custom post type called "case_studies" and it has 3 categories: "seo", "website-design" and "facebook-advertising".

I have several posts in the main page, and for each post I want to output what categories the post has.

For example, the latest post has a category of "seo" and "facebook-advertising", and I want it to be displayed in the page.

I have tried the get_the_terms(); function but I think I am using it incorrectly.

Here is the code of the page:

<div class="container">
<!--
<div class="category_container">
    <p class="category_item" id="all">All</p>
    <p class="category_item" id="website">Websites</p>
    <p class="category_item" id="facebook">Facebook Ads</p>
    <p class="category_item" id="seo">SEO</p>
</div>
-->
<div class="row d-flex">
        <?php

           $args1 = array( 'post_type' => array('case_studies'), 'order' => 'DESC', 'posts_per_page' => 30, 'orderby' => 'date' );
           $loop = new WP_Query( $args1 );

           while ( $loop->have_posts() ) { 

           $loop->the_post();

           $feat_image = wp_get_attachment_url( get_post_thumbnail_id($loop->ID));  

        ?>
        <div class="col-sm-4">
             <div class="case-study-content">
                    <a href="<?php the_permalink() ?>" class="blog_blocks">
                        <div class="b_image">
                            <img src="<?php echo get_the_post_thumbnail_url(); ?>"/>
                        </div>
                        <div class="b_h_sec">
                        <h2><?php the_title(); ?></h2>
                        <p><?php echo wp_strip_all_tags( get_the_excerpt(), true ); ?></p>
                        <span class="r_m">Read More</span>
                        </div>
                    </a>
             </div>
        </div>

        <?php } ?>

        <?php wp_reset_postdata(); ?>
</div>
 </div>

Here is how the output looks right now and where I want categories to be displayed.

enter image description here

0 Answers