Get all categories from custom post type in WordPress
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">
<?php
$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>
</a>
<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>
</div>
</div>
<?php
}
?>
</div>
</div>
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">
<?php
$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>
</a>
<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>
</div>
</div>
<?php
}
?>
</div>
</div>
Recommanded Articles
- Generate Dummy Posts in WordPress
- How to add captcha in Contact Form 7
- how to create a cron job in wordpress
- How to get form data in Contact Form 7
- Insert Update Delete Select query in WordPress
- How to increase website speed
- Create plugin in WordPress in which create table in DB on activate
- Create new tab under my account WooCommerce frontend
- Custom image sizes in WordPress
- Get posts by meta key and meta value in WordPress
Latest Comments