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>
and
<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 !
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>
and
<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 !
Share Improve this question asked Oct 30, 2018 at 18:06 NicautreNicautre 213 bronze badges 1 |1 Answer
Reset to default 0To print or to call all the slugs, you can use the following codes.
<?php
$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
$cat
? – Milo Commented Oct 31, 2018 at 4:18