Search code examples
wordpressadvanced-custom-fields

Category slug - Custom post type Wordpress


With custom post type, i need to use category slug for my class (css).

<?php 
            global $post;
            $terms = wp_get_post_terms($post->ID, 'typeresources');
            if ($terms) {
                $output = array();
                foreach ($terms as $term) {
                if ($term->term_id != 14)
                {
                $output[] = '<div class="cat-resources">' .$term->name .'</div>';
                }
                }
                echo join( ' ', $output );
            };
            ?>

Would like to add at my "cat-resources class" the categroy slug

How can i do that ?


Solution

  • There you go.

    global $post;
    $terms = wp_get_post_terms($post->ID, 'typeresources');
    if ($terms) {
        $output = array();
        foreach ($terms as $term) {
            if ($term->term_id != 14) {
                $output[] = '<div class="cat-resources '.$term->slug.'">' .$term->name .'</div>';
            }
        }
        echo join( ' ', $output );
    };