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

Advertisements

Sr. Software Engineer

Tagged with: , ,
Posted in Wordpress
One comment on “How get the categories title of any post using custom query: WordPress
  1. Branden says:

    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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: