How to List All the Categories for Custom Post Type

If you just want to list the custom post categories (taxonomies), then you can use the get_terms function.

The get_the_terms filter will be called when the cache has the term and will pass the found term along with the array of $taxonomies and array of $args.

<?php $taxonomy = 'books'; ?>
<?php $terms = get_the_terms($post_id, $taxonomy);?>
<?php if ($terms && !is_wp_error($terms)) : ?>
    <div class="tagcloud">
        <?php foreach ($terms as $term): ?>
            <a href="<?php echo get_term_link($term->slug, $taxonomy) ?>"><?php echo $term->name ?></a>
        <?php endforeach; ?>
    </div>
<?php endif;?>

-Advertisement-

Join The Discussion

Please note: We reserve the right to delete comments that contains snarky remarks, offensive or off-topic. To know more read our comments policy.