How get the categories title of any post using custom query: WordPress

Hello Friends!
If you want to get the posts category title on your custom template, then don’t worry :) just use my code given below :

$post_categories = wp_get_post_categories('INSERT_POST_ID_HERE');
$cats = array();
foreach($post_categories as $c){
	$cat = get_category( $c );
	$cats[] = array( 'name' => $cat->name, 'slug' => $cat->slug );
}
foreach($cats as  $index=>$val){
echo "Category Name: ".$val['slug']."<br>";
}

Enjoy Code! | Raghunath Blog

One Reply to “How get the categories title of any post using custom query: WordPress”

  1. Although blogging for fun can be relatively easy, blogging for profit
    is not. This helps the first time traveller to handle
    up with the odd environment inside a plane.

Leave a Reply

Your email address will not be published. Required fields are marked *