Home » Webtips » WordPress – Get Parent Category ID

WordPress – Get Parent Category ID

The top most parent category id of a post can be retrieved by using this three line code.

The first line will get the category of the current post.

The second line will create an object of the first category of the post.

Here the id of the first category can be get by using the code $category[0]->term_id

Finally the parent category id can be retrived by using

Now parent category id will be in the variable $parent_catid

About the author


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.

1 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.