/ Published in: PHP
                    
                                        
Just insert any category id into the argument and it will return the top level category object.
e.g: print_r( get_top_level_category('INSERT CATEGORY ID HERE') );
                e.g: print_r( get_top_level_category('INSERT CATEGORY ID HERE') );
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
function get_top_level_category($id){
$category = get_category($id);
$parent_category = NULL;
if($category->category_parent != 0){
$parent_category = get_top_level_category($category->category_parent );
} else {
$parent_category = get_category($category->cat_ID);
}
return $parent_category;
}
}
Comments
 Subscribe to comments
                    Subscribe to comments
                
                