I have created a filter on a custom post type loop using terms slugs just like that :

<li><a href="#" data-filter=".<?php echo esc_attr( $cat->slug ); ?>"><?php echo esc_html( $cat->name ); ?> </a></li>


<div class="grid-item <?php echo esc_attr( $cat->slug ); ?> js-isotope-item js-grid-item">

But several posts are linked to multiple taxonomy terms and $cat->slug just take the first slug..

Is there any way to call all the slugs and output them with a separator (space) to have different classes ?

Sorry if I'm not clear, english is not my language..

Thank you for help !

  • Where do you set the value for $cat?
    – Milo
    Oct 31, 2018 at 4:18

1 Answer 1


To print or to call all the slugs, you can use the following codes.

$cats = get_the_terms(get_the_id(), 'your-taxonomy-id');
   if( is_array($cats) ){
      foreach ( $cats as $cat ) {
           echo $cat->slug.' ';

For more details, follow the below link.
Add custom category name as data-filter to switch between these categories

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.