/ Published in: PHP
Just insert any category id into the argument and it will return the top level category object.
e.g: printr( gettoplevelcategory('INSERT CATEGORY ID HERE') );
Expand |
Embed | Plain Text
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; } }
You need to login to post a comment.
