I have a list of the latest posts (custom post type). In each list item, I have the title of the post and an image. I’d like to show the term name that the post is a part of. How would I go about doing that? In the code I have CUSTOM TAXONOMY TERM NAME HERE where I’d like to show the term.

<?php
                    $args = array( 
                        'post_type' => 'lessons', 
                        'posts_per_page' => 4, 
                        'order'=> 'ASC', 
                        'orderby' => 'title',
                        'taxonomy' => 'lesson-type'
                    );
                    $postslist = get_posts( $args );

                    foreach ( $postslist as $post ) : setup_postdata( $post ); ?>
                        <div class="col-sm-6 col-md-3">
                            <div class="panel panel--lesson">
                                <img src="http://placehold.it/640x360" alt="<?php the_title() ?>" class="video-thumb img-responsive" data-vimeo-id="<?php the_field('vimeo_id') ?>">
                                <div class="panel-body">
                                    <h3><?php the_title() ?></h3>

                                    <ul>
                                        <li><span>Category: CUSTOM TAXONOMY TERM NAME HERE</span> </li>

                                        <?php 
                                            $songDifficulty = get_field('song_difficulty');
                                            if ($songDifficulty > 0) : ?>
                                                <li><span>Song Level:</span> <?php echo $songDifficulty ?></li>
                                            <?php endif; ?>
                                    </ul>

                                    <a href="<?php echo get_permalink(); ?>" class="cta cta--primary cta--chevron-right cta--block">View Lesson</a>
                                </div>
                            </div>
                        </div>
                <?php
                    endforeach; 
                    wp_reset_postdata();
                ?>

Read more here: Getting taxonomy term for each listed post


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: