Home » Webtips » Get Parent Category ID of Current Category
Webtips

Get Parent Category ID of Current Category

Get the parent category ID from the current category ID in WordPress. The Function will return the Parent Category ID.

1. Include the function in your function.php page.

2. Call the function from the page in which you want the parent category id.

Here $cur_cat_id contains the category id which id obtained from the function get_query_var(‘cat’), which is called in the category.php page to obtain current category id.

If you are using the function in any other page in which you know the current category id, simply assign the value to $cur_cat_id, to obtain its parent category ID.

Now after calling the function get_categories_parent_id( $cur_cat_id ), you will have the parent category ID in $parent_catid.

About the author

Vipin

Hi, i am Vipin, a programmer working in Dubai, UAE. I love blogging, and so started TechRounder for sharing my findings and other digital informations with others too. Please feel free to share your feedback with me in the comment section below or you can email me at vipin@techrounder.com.

Add Comment

Click here to post a comment

Your email address will not be published. Required fields are marked *

Get latest updates
in your inbox

Subscribe to TechRounder mailing list and get interesting stuff and updates to your email inbox.

Thank you for subscribing.

Something went wrong.