Home » Labs » How to get ID of parent category in WordPress  

How to get ID of parent category in WordPress


Filed under Labs

Some times you need to get ID of the parent category. Here is the code which will display the ID of parent category. this code will work fine with WordPress versions 1.5.1 and above.

 
	<?php
	if( is_category() ) {
	  $query_cat = get_query_var('cat');
	  $cat = get_category( $query_cat );
	  echo $cat->category_parent; // Display the ID
	}
	?>

Posts you may like: