Get all categories from custom post type

Get all categories from custom post type

In this blog I will get all the categories of custom post type using taxonomy. For this I've created post type books using Post Type Generator nd my taxonomy is post_book. To get all categories of custom post type I'm going to pass arguments in get_terms() function.
Use below code to get categories of custom post types `books`

<div class="container">
    <div class="row">
            $args = array(
                        'taxonomy' => 'post_book',
                        'number' => '-1',
                        'orderby' => 'name',
                        'order'   => 'ASC'

            $cats = get_categories($args);
            foreach($cats as $cat) {
                <div class="col-md-4">
                    <div class="inner_column">
                        <a title="<?php echo $cat->name; ?>" href="<?php echo get_category_link( $cat->term_id ); ?>?">
                            <h3><?php echo $cat->name; ?></h3>
                        <p><?php echo $cat->description; ?></p>
                        <a title="<?php echo $cat->name; ?>" class="readmore" href="<?php echo get_category_link( $cat->term_id ) ?>"> READ MORE </a>


Hi, I'm Saurav, the developer behind usingphp. Donate to help me keep usingphp free and maintained.

Please let me know what your thoughts or comments are on this article. If you have any suggestion or found any mistake in this article then please let us know.

Latest Comments

Add your comment