madeinthearcade
6/6/2017 - 10:57 AM

Register custom taxonomies for CPT. This allows Wordpress to assign categories only CPT and then you can show these categories.

Register custom taxonomies for CPT. This allows Wordpress to assign categories only CPT and then you can show these categories.

// Create CPT specific categories
function tr_create_my_taxonomy() {
    register_taxonomy(
        'tenants-categories', ---- this is important
        'tenants',
        array(
            'label' => __( 'Categories' ),
            'rewrite' => array( 'slug' => 'tenants-categories' ),
            'hierarchical' => true,
        )
    );
}
add_action( 'init', 'tr_create_my_taxonomy' );

<?php
$terms = get_the_terms( $post->ID , 'tenants-categories' );
foreach ( $terms as $term ) {
echo $term->name;
}
?>