Display multiple custom taxonomy values on single custom post types page?

I can’t seem to figure this out, I have tried and looked at multiple forums posts with example codes but nothing is working for me.

I have wordpress and a custom post type called videos-on-demand.

Video on demand post type has a few taxonomies like age, teachers, length of video, etc..

I created a test post and made a custom page that is working and I am able to customize it… however I can’t get the taxonomies to show on the footer of the page similar to how you would see categories and tags on a standard blog post.

I want to be able to click on those terms/links to bring you to an archive of all those terms for searchability.

What am I missing here?

<?php 
    $terms = get_the_terms( $post->ID, 'video-on-demand' ); 
    foreach($terms as $term) {
      echo $term->name;
    }
?>

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

The first line of code in your question appears to be the problem.

The get_the_terms() function expects the post (object or ID) as the first parameter. The second parameter should be the taxonomy name, not your custom post type.

Something like this should work for you:

$age_terms = get_the_terms( $post->ID, 'age' );
$lang_terms = get_the_terms( $post->ID, 'language' );

get_the_terms( int|WP_Post $post, string $taxonomy )
https://developer.wordpress.org/reference/functions/get_the_terms/


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x