customization – How to show parent taxonomy using get_the_terms?

Question

I have registered one custom taxonomy. And I am using these codes to show this taxonomy on single.php

But it showing all parent as well child terms.

function showorganisation()
{
    $terms = get_the_terms($post->ID, 'organization');
    foreach ($terms as $term) {
        $term_link = get_term_link($term, 'organization');
        if (is_wp_error($term_link))
            continue;
        echo '<a href="' . $term_link . '">' . $term->name . '</a>';
    }
}

I wanT to parent terms only.

0
Prabhat Jani 5 months 2022-03-01T23:04:27-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse