Support » Fixing WordPress » Get taxonomy slug

  • Meaby someone can help me. I need to use taxonomy slug us li class for my portfolio theme.

    Here is my code. It only get’s taxonomy name but I need taxonomy slug.

    <li class="<?php $terms_as_text = get_the_term_list( $post->ID, 'myportfolio', '', ' ', '' ) ;
    echo strip_tags($terms_as_text); ?> all">

    Thanks. 🙂

Viewing 1 replies (of 1 total)
  • im trying to do this exact same thing and have the exact same problem. cant figure out how to convert name to slug…

    i did get this working, but when you assign 2 categories to a post it acts kinda funny. It doesnt list all of the categories in a row to use as class identifiers

     $taxonomy = 'your custom taxonomy';
     $terms = get_the_terms( $post->ID , $taxonomy );
        if ( !empty( $terms ) ) :
        foreach ( $terms as $term ) {
          $link = get_term_link( $term, $taxonomy );
          if ( !is_wp_error( $link ) )
          echo '<li class="all ' . $term->slug . '">';

    hoping someone knows the right way to do this. ive been working on this for days.

Viewing 1 replies (of 1 total)
  • The topic ‘Get taxonomy slug’ is closed to new replies.