How to get post category title within the loop?

I’m stuck in a rather simple task: to get the category title for the current post, within the loop, to be used in the function (not to be automatically printed). Any ideas?

1 Answer
1

The function get_the_category() returns an array of category objects. To get the name of the first category, use this:

$categories = get_the_category(); 
$cat_name = $categories[0]->cat_name;

For a list of the properties of the category object, see the documentation on get_the_category()

Leave a Comment