Skip to main content
modify to show how to do more terms (another taxonomy)
Source Link
GhostToast
  • 4.6k
  • 3
  • 28
  • 44

The function you mention is going to return a list of links -- aren't you just trying to get the term slug as a class? Why not do....

$terms = get_the_terms($post->ID, 'my-category');
$more_terms = get_the_terms($post->ID, 'another-category');

$slug_out = array(); 

foreach($terms as $term){
    $slug_out[] = $term->slug;
}

foreach($more_terms as $term){
    $slug_out[] = $term->slug;
}

echo '<div class="'.implode(', ', $slug_out).'">';

The function you mention is going to return a list of links -- aren't you just trying to get the term slug as a class? Why not do....

$terms = get_the_terms($post->ID, 'my-category');
$slug_out = array();
foreach($terms as $term){
    $slug_out[] = $term->slug;
}

echo '<div class="'.implode(', ', $slug_out).'">';

The function you mention is going to return a list of links -- aren't you just trying to get the term slug as a class? Why not do....

$terms = get_the_terms($post->ID, 'my-category');
$more_terms = get_the_terms($post->ID, 'another-category');

$slug_out = array(); 

foreach($terms as $term){
    $slug_out[] = $term->slug;
}

foreach($more_terms as $term){
    $slug_out[] = $term->slug;
}

echo '<div class="'.implode(' ', $slug_out).'">';
Source Link
GhostToast
  • 4.6k
  • 3
  • 28
  • 44

The function you mention is going to return a list of links -- aren't you just trying to get the term slug as a class? Why not do....

$terms = get_the_terms($post->ID, 'my-category');
$slug_out = array();
foreach($terms as $term){
    $slug_out[] = $term->slug;
}

echo '<div class="'.implode(', ', $slug_out).'">';