Define a function returns the current category id
function getCurrentCatID(){
global $wp_query;
if(is_category() || is_single()){
$cat_ID = get_query_var(‘cat’);
}
return $cat_ID;
}
Call the function “get_category() ” to fetch the current category details
$category = get_category( getCurrentCatID() );//
$parentID = $cat->category_parent;
echo $parentID;