Dukeo » WordPress » Category ID: How To Get It From Category Name

Category ID: How To Get It From Category Name

Steven 2 responses WordPress

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:

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):

$cat_ID = get_category_id('Category Name');

If you enjoyed this article,
Get email updates

Join for Free »


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