1

Thanks to GhostToast for helping me on my way with this post.

Now I am successfully able to echo out all of the taxonomy associated terms dynamically. However, this unfortunately also seems to spit out all the site's post_tags too.

So how can I use the following code, but not show the standard post_tags (I'd like to keep the post_tags available for use, just not show them as a result of this query)

// 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>";
    }
}
}

2 Answers 2

1

Use this function to determine if Taxonomy is hierarchical or not:

Function Reference/is taxonomy hierarchical « WordPress Codex

Example:

// taxonomy term archives
$post_type = get_post_type();
$taxonomies = get_object_taxonomies($post_type);
if(!empty($taxonomies)){
foreach($taxonomies as $taxonomy){
    // only want hierarchical -- no tags please
    if(is_taxonomy_hierarchical($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>";
        }
    }
}

} // this was missing
5
  • Thank you GT! Unfortunately that results in Fatal error: Call to undefined function is_taxonomy_hierarchial(). Googling it appears to show many sites with the same issue, but no actual answers. Presumably I need to add something to functions file? Jun 18, 2013 at 16:55
  • 2
    Oops. Was typo. hierarchical == tough word.
    – GhostToast
    Jun 18, 2013 at 16:58
  • lol - I missed that too! Sending you a big high five along with a crate of your favourite wishes for the day (and a spell chekrr). Thanks HEAPS GhostToast!! :-) Would be happy to connect with you socially if you're on G+ or Twits? Jun 18, 2013 at 17:10
  • I hang out in WPSE chat if you wanna shoot the breeze sometime chat.stackexchange.com/rooms/6/the-loop. Please mark answer as accepted if this answer works for you, thanks.
    – GhostToast
    Jun 18, 2013 at 17:12
  • Done. All good - cheers Jun 18, 2013 at 17:15
1

Not sure what you mean by "I'd like to keep the post_tags available for use" but I see two options here:

$post_type = get_post_type();
$taxonomies = get_object_taxonomies($post_type);
$taxonomies = array_diff($taxonomies,array('post_tag'));
// and then your Loop

Or ...

$post_type = get_post_type();
$taxonomies = get_object_taxonomies($post_type);
if(!empty($taxonomies)){
  foreach($taxonomies as $taxonomy){
    if ('post_tag' === $taxonomy) continue;
    $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>";
    }
  }
}
2
  • Thanks for your answer. GhostToast's answer worked perfectly for me. Jun 18, 2013 at 17:17
  • No need to post "thank you" comments. That is what voting is for :)
    – s_ha_dum
    Jun 18, 2013 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.