I understand WordPress concept “primary category”, but I do not understand how to fetch the name of the highest category in the hierarchy for a specific post?
Having this code:
$category_obj = get_the_category( $post_id );
$category_name = $category_obj[0]->cat_name;
would fetch the category’s name of the post, but this category is only the first category listed for the post and that category is not always the primary category.
I’m using this outside of “the loop”.