How can i list custom post type categories?

I have a custom post type called “us_portfolio”. And i do have portfolio categories for each of my product type.
What i need is listing the portfolio categories in my home page. I am not expert so can you please assist me about this issue please?
I can provide any code you need.

You can see that there is 4 recent works in the second section.
I need to change this “recent_works” area to listing custom post type categories.
How can i make this ? can you please help me idiot proof?

Thank you for your time…

enter link description here

1 Answer
1

This will list the 3 most recent posts from the post type us_portfolio.

       <?php
    $args = array(
        'posts_per_page' => 3,
        'post_type' => 'us_portfolio'
    );

    $custom_query = new WP_Query($args);
    while ($custom_query->have_posts()) :
        $custom_query->the_post();
        ?>

                    <div class="image bg-image" style="background-image: url('<?php the_post_thumbnail_url('full'); ?>')"></div>

             <?php the_category(); ?>
                <h3>
                    <a title="<?php the_title(); ?>"  href="https://wordpress.stackexchange.com/questions/289627/<?php the_permalink(); ?>">
                        <?php the_title(); ?>
                    </a>
                </h3>
            <a href="https://wordpress.stackexchange.com/questions/289627/<?php the_permalink(); ?>">">Read More</a>
    <?php endwhile; ?>

We are using WP_query to achieve this.
You can learn more about WP_Query here: https://codex.wordpress.org/Class_Reference/WP_Query

Leave a Comment