Show Custom Taxonomy Slug(s)?

can anyone help me with this?

I need to print the slug of my custom taxonomy, can this be done?

The following kind of works but it just shows the name, rather than the slug which i need for a class purpose..

<?php $terms = get_the_terms( $post->ID , 'area' ); foreach( $terms as $term ) {print $term->name; unset($term);}?>     

Any way of just getting the slug for my custom taxonomy ‘area’ ??

Many thanks for any help 🙂

1 Answer
1

$term->slug

Here is an example return of $term:

 stdClass Object (
                  [term_id] => 31
                  [name] => Architectural Items / Salvage
                  [slug] => architectural-items-salvage
                  [term_group] => 0
                  [term_taxonomy_id] => 31
                  [taxonomy] => dcategory
                  Show Custom Taxonomy Slug(s)? =>
                  [parent] => 5
                  [count] => 10
                  [object_id] => 197
                 )

If you don’t know what’s in $term or any other variable then print_r() and var_dump() are your friend.

Leave a Comment