{"id":4692,"date":"2012-07-26T15:04:46","date_gmt":"2012-07-26T15:04:46","guid":{"rendered":"https:\/\/www.techrounder.com\/blog\/wordpress-get-parent-category-id\/"},"modified":"2026-01-04T11:36:57","modified_gmt":"2026-01-04T11:36:57","slug":"wordpress-get-parent-category-id","status":"publish","type":"post","link":"https:\/\/www.techrounder.com\/blog\/wordpress-get-parent-category-id\/","title":{"rendered":"WordPress &#8211; Get Parent Category ID"},"content":{"rendered":"<p>You can retrieve the topmost parent category id of a post by using this three-line code.<\/p>\n<pre lang=\"php\" line=\"1\">$category = get_the_category();\r\n$cat = get_category($category[0]->term_id);\r\n$parent_catid = $cat->category_parent;<\/pre>\n<p>The first line will get the category of the current post.<\/p>\n<p>The second line will create an object of the first category of the post.<\/p>\n<p>Here the id of the first category can be get by using the code <strong>$category[0]-&gt;term_id<\/strong><\/p>\n<p>Finally, you can retrieve the parent category id by using<\/p>\n<pre lang=\"php\" line=\"1\">$parent_catid = $cat-&gt;category_parent;<\/pre>\n<p>Now parent category id will be in the variable <strong>$parent_catid<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"You can retrieve the topmost parent category id of a post by using this three-line code. $category =&hellip;","protected":false},"author":2,"featured_media":1482,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"csco_display_header_overlay":false,"csco_singular_sidebar":"","csco_page_header_type":"","csco_page_load_nextpost":"","csco_post_video_location":[],"csco_post_video_location_hash":"","csco_post_video_url":"","csco_post_video_bg_start_time":0,"csco_post_video_bg_end_time":0,"csco_post_video_bg_volume":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-4692","post","type-post","status-publish","format-standard","has-post-thumbnail","category-webtips","cs-entry","cs-video-wrap"],"_links":{"self":[{"href":"https:\/\/www.techrounder.com\/blog\/wp-json\/wp\/v2\/posts\/4692","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.techrounder.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techrounder.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techrounder.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techrounder.com\/blog\/wp-json\/wp\/v2\/comments?post=4692"}],"version-history":[{"count":0,"href":"https:\/\/www.techrounder.com\/blog\/wp-json\/wp\/v2\/posts\/4692\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.techrounder.com\/blog\/wp-json\/wp\/v2\/media\/1482"}],"wp:attachment":[{"href":"https:\/\/www.techrounder.com\/blog\/wp-json\/wp\/v2\/media?parent=4692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techrounder.com\/blog\/wp-json\/wp\/v2\/categories?post=4692"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techrounder.com\/blog\/wp-json\/wp\/v2\/tags?post=4692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}