I wrote this function to solve this problem (excuse me if I’m not following php best practices, I’m new to php…old pro at JSPs though)
function get_current_location(){
$locations_cat_id = 2;
$ignore_ids = array();
$ignore_ids[] = $locations_cat_id;
$cats = get_categories( array( 'child_of'=>$locations_cat_id, 'parent'=>$locations_cat_id, 'hide_empty'=>0 ) );
foreach($cats as $c){
$ignore_ids[] = $c->cat_ID;
}
foreach((get_the_category()) as $category) {
if ( !in_array($category->cat_ID, $ignore_ids) && cat_is_ancestor_of( $locations_cat_id, $category->cat_ID )) {
return $category->cat_name;
}
}
return "";
}