Get wordpress taxonomy slug name(s) to use as div class
I'm trying to mark up my posts using their custom taxonomy slug as the div class so that they can be filtered...
So far what I have displays the taxonomy name but what I need is the slug so I have a nice-space-free-name, I have the below so far outputting the name:
<div class="box-item cocktails-box
<?php $terms_as_text = strip_tags( get_the_ter开发者_运维问答m_list( $wp_query->post->ID, 'cocktail_type', '', ' ', '' ) );
echo $terms_as_text; ?>">
Try wp_get_post_terms()
. It will return an array of objects instead of echoing a comma delimited list, one of the object parameters being the slug.
Check it out: wp_get_post_terms
in the codex
精彩评论