Reputation: 125
I have child category id in wordpress and i want to get parent category name for the same.i just want to fetch the parent category name only...
Upvotes: 0
Views: 1136
Reputation: 837
You can use this kind of function :
function get_category_parent($child_id, $link=false, $nicename=false){
$return = '';
$parent = &get_category($child_id);
if(is_wp_error($parent)) return $parent;
if($nicename){
$name = $parent->slug;
}else{
$name = $parent->cat_name;
}
if($link){
$return .= '<a href="'.get_category_link($parent->term_id).'">'.$name.'</a>';
}else{
$return .= $name;
}
return $return;
}
Upvotes: 1