Get my FREE ebook:
"SEO FOR BLOGS: The Ultimate Guide"
Limited Time Offer!

How To Get WordPress Category ID From Category Name

Every person who already worked on developing a WordPress-based website have faced this question: How to get a category ID? There are plenty of reason you could need to get a Category ID, for example customizing your pages for a given category.

To easily retrieve a Category ID from a Category name, simply paste the following code in the functions.php file of your WordPress theme:

1
2
3
4
5
6
7
function get_category_id($cat_name){
	$term = get_term_by('name', $cat_name, 'category');
	return $term->term_id;
}

From this point, all you need to do is call this new function when you want to get a Category ID from a Category name (don’t forget to edit the category name):

1
$cat_ID = get_category_id('Category Name');
Commenting Contest
If you enjoyed this article, Get email updates
(It's Free)
Sté Kerwer
Post written by: Sté Kerwer
Bonjour from France. My name is Stéphane Kerwer and Dukeo.com is my blog. I do most of the heavy lifting in here but from time to time, you may see some guest posts. If you wish to receive updates about Dukeo, subscribe to RSS Feed, follow Dukeo on twitter or become a fan on Facebook.
One Comment
  1. Painless Teething
    Painless Teething

    Its a good post to be used but can you also suggets a simpler way to find the category as I just need to know it for mentioning it in the Menus page once and do not need to recall the same over and over again.
    Any ways thanks for the post and trying ot help people like me.

arrow