WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom taxonomy terms as slugs/single words (2 posts)

  1. masok88
    Member
    Posted 2 years ago #

    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!

  2. masok88
    Member
    Posted 2 years ago #

    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 . " ";
    
         }
     }?>"

Topic Closed

This topic has been closed to new replies.

About this Topic