Get Parent Category Detail from Child Category

If you are on category page so you can get detail easily of current category using below query.

global $wp_query; // get the query object
$cat_obj = $wp_query->get_queried_object();

//Using above code you will get taxonomy , term_id and other details of current category.
//After you can use below code to get parent category details  if current category have parent.

if($cat_obj->category_parent!=0)
{
 $parent_term = get_term_by( 'id', $cat_obj->category_parent, $cat_obj->taxonomy);
 $termid = $parent_term->term_id;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s