Get category id by name

/ Published in: PHP
Save to your folder(s)

How to get a category id from the name of the category

Copy this code and paste it in your HTML
  1. function get_category_id($cat_name){
  2. $term = get_term_by('name', $cat_name, 'category');
  3. return $term->term_id;
  4. }

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.