{"id":309,"date":"2012-01-05T17:47:24","date_gmt":"2012-01-05T08:47:24","guid":{"rendered":"http:\/\/www.santoshkori.com\/blog\/?p=309"},"modified":"2012-08-23T17:31:11","modified_gmt":"2012-08-23T08:31:11","slug":"get-category-slug-using-category-id-in-wordpress-cms","status":"publish","type":"post","link":"https:\/\/www.santoshkori.com\/blog\/get-category-slug-using-category-id-in-wordpress-cms\/","title":{"rendered":"Get category slug using category ID in WordPress cms"},"content":{"rendered":"<p>In one of my recent freelance works, I had to play a lot with categories. I was looking for an easy way to get a category slug using an ID, and I found this great function that I\u2019d like to share with you today. <\/p>\n<p>First, put the following function in your functions.php file:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nfunction get_cat_slug($cat_id) {\r\n\t$cat_id = (int) $cat_id;\r\n\t$category = &amp;get_category($cat_id);\r\n\treturn $category-&gt;slug;\r\n} \r\n<\/pre>\n<p>Once done, you can call the function as shown below:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php echo get_cat_slug(3); ?&gt;\r\n<\/pre>\n<p>This will display the slug for the category with the ID 3. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>In one of my recent freelance works, I had to play a lot with categories. I was looking for an easy way to get a category slug using an ID, and I found this great function that I\u2019d like to share with you today. First, put the following function in your functions.php file: function get_cat_slug($cat_id) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,5],"tags":[155,154,153,725],"class_list":["post-309","post","type-post","status-publish","format-standard","hentry","category-tips-n-tricks","category-wordpress","tag-get-category-slug-using-category-id","tag-get-category-slug-using-category-id-in-wordpress","tag-get-category-slug-using-category-id-in-wordpress-cms","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/309","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/comments?post=309"}],"version-history":[{"count":3,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/309\/revisions"}],"predecessor-version":[{"id":700,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/309\/revisions\/700"}],"wp:attachment":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/media?parent=309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/categories?post=309"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/tags?post=309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}