Get custom post’s category in wordpress
In wordpress we easily can get the category details of post. I have written a custom function to make it easy to use.
//Call from theme
$catname=getAllcustomPostCat('post');
print_r($catname);
//Put it into functions.php
function getAllcustomPostCat($postType)
{ $args=array(
'post_type' => $postType,
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1);
$my_query = null;
$my_query = new WP_Query($args);
global $post;
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post();
$category = get_the_category( $post->ID);
$firstCategory[] = $category[0]->cat_name;
endwhile;
}
return $firstCategory;
wp_reset_query();
}