Support » Fixing WordPress » Custom taxonomy terms as slugs/single words

  • Resolved masok88

    (@masok88)


    Hey I’m trying to create something that will grab a particular set of terms from a custom taxonomy associated with an entry (so in the loop) into the class field of a div.

    I can get this easy enoug using..

    <?
    			 $terms = get_terms("taxonomy-name");
    
     $count = count($terms);
     if ( $count > 0 ){
         foreach ( $terms as $term ) {
           echo "" . $term->name . " ";
    
         }
     }?>

    but the problem is with any spaces that appear in the terms say ‘apple pie’ I want it to render as applepie or apple-pie. I’ve been trying to figure this out for ages but can’t for the life of me. Any help would be much appreciated!

Viewing 1 replies (of 1 total)
  • Sorry,

    Figured it out! Just had to add..

    <?
    			 $terms = get_terms("taxonomy-name");
    
     $count = count($terms);
     if ( $count > 0 ){
         foreach ( $terms as $term ) {
         $nospaceterm = str_replace (" ", "", $term->name);
    
           echo "" . $nospaceterm . " ";
    
         }
     }?>"
Viewing 1 replies (of 1 total)
  • The topic ‘Custom taxonomy terms as slugs/single words’ is closed to new replies.