Display custom post type taxonomy in a WordPress excerpt for current post

Question

Hi there and thanks in advance for any help. I am trying to display custom taxonomies(Themes and Guests)on the current post (of custom post type, Podcasts). I have tried the code below, but I am getting an empty result ie. nothing is showing. I added $post->ID after I realised that the code was working fine, but was displaying ALL categories, not just the ones for the current post.

    add_filter( 'the_excerpt', function( $excerpt ) {

        $themes = get_terms($post->ID,'themes',
            array(
                'hide_empty' => false,
                'orderby'    => 'name',
                'order'      => 'ASC'
            )
        );?> 
         <p><?php
        foreach( $themes as $theme ):
            ?>    
           <span class="theme"><?php echo $theme->name; ?></span>
        <?php endforeach;?></p><?php
         $guests = get_terms($post->ID,'guests',
            array(
                'hide_empty' => false,
                'orderby'    => 'name',
                'order'      => 'ASC'
            )
        );?> 
         <div class="guest-wrap"><span class="guest-label">Episode Guests: </span>
        <?php
        
        foreach($guests as $guest ):
            ?>  
           <span class="guests"><?php echo $guest->name; ?></span>
        <?php endforeach;?></div><?php
    $player = get_post_meta( get_the_ID(), 'embed_episode_code', true );
    return $player . $excerpt;
} );

0
user2696536 2 months 2021-06-15T21:06:49-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse