get_post_terms not working as expected

I misunderstood what you were trying to do before. I thought you wanted to list the terms associated with one particular post – the one you are on. Whoops!

Try this instead:

    $terms = get_terms('fruit_category');
    if(!empty($terms)){ 
        echo "<ul>";
        foreach ( $terms as $term ) {
            echo '<li><a href="'.get_term_link($term->slug, 'fruit_categories').'">'. $term->name . "</a></li>";
        }
        echo "</ul>";
    }

This will get you a list of all the links to the term pages, provided each term has at least one post in it.

Update:

To get taxonomy terms a bit more dynamically, can do this:

// taxonomy term archives
$post_type = get_post_type();
$taxonomies = get_object_taxonomies($post_type);
if(!empty($taxonomies)){
    foreach($taxonomies as $taxonomy){
        $terms = get_terms($taxonomy);
        if(!empty($terms)){ 
            echo "<ul>";
            foreach ( $terms as $term ) {
                echo '<li><a href="'.get_term_link($term->slug, $taxonomy).'">'. $term->name . "</a></li>";
            }
            echo "</ul>";
        }
    }
}

Leave a Comment