Display the current custom taxonomy name of a custom post type!

I am building a custom theme and have created a custom post type called “knowledgehub” with it’s own custom taxonomy called “knowledgehub_topic”.

What i’m trying to do seems simple on the surface. I want to display the “knowledgehub_topic” that the current “knowledgehub” has been assigned.

After much googling and digging about in the WordPress codex, i figured it might be time to ask a professional instead! :^)

  • Majid
    • Recruit

    Hi Daniel !

    I hope you are doing great today :slight_smile:

    Can you please try the following code, make sure you have access to the $post->ID, otherwise it won’t work.

    // get_the_terms will return an array of the taxonomies the post is assigned to
    // https://developer.wordpress.org/reference/functions/get_the_terms/
    $terms = get_the_terms( $post->ID, 'knowledgehub_topic' );
    // Loop through them and dislay them
    foreach($terms as $term) {
    echo $term->name;
    }

    Let me know how did it go.

    Cheers,

    Majid

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.