Wordpress: Get category ID from category name


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



Copy this code and paste it in your HTML
  1. $my_cat_name = "news";
  2.  
  3. $my_cat_id = get_term_by('name', $my_cat_name, 'category')->term_id;
  4.  
  5. echo $my_cat_id; //1

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.