Get Category ID using Category Name

Simple Get Category ID using Category Name

Today, We want to share with you PHP word-press Find Category Id.In this post we will show you get category id by slug, hear for How to get post, page or category ID in WordPress we will give you demo and example for implement.In this post, we will learn about How to get post, page or category ID in WordPress with an example.

List of all Google Adsense, VueJS, AngularJS, PHP, Laravel Examples.

woocommerce get current category id

There are the Following The simple About get term id by name Full Information With Example and source code.

As I will cover this Post with live Working example to develop Fetch category_id by cat name wp, so the get category id by category name wp for this example is following below.

Simple Get Category ID using Category Name

function get_category_id($cat_name){
  $catData = get_term_by('name', $cat_name, 'category');
  return $catData->term_id;

wordpress Usage

$category_ID = get_category_id('clothing');

get current category ID php

$category = get_queried_object();
echo $category->term_id;

Get the id of a WooCommerce category, by cat name

$category = get_term_by( 'slug', 'mobile', 'product_cat' );
$cat_id = $category->term_id

Get current category ID of the active page

$categories = get_the_category();
$category_id = $categories[0]->cat_ID;

$category = get_category( get_query_var( 'cat' ) );
$cat_id = $category->cat_ID;

WordPress Get Category ID from Slug

$slug = 'mobiles';
$cat = get_category_by_slug($slug); 
$catID = $cat->term_id;

Web Programming Tutorials Example with Demo

Read :


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about wordpress get category name in loop.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Related FAQ

Here are some more FAQ related to this Article:

  1.   Advanced jQuery Ajax Pagination PHP MySQL using jQuery
  2.   vue Image Upload Component
  3.   Vue.js Binding Fundamentals Using V-Bind Directive
  4.   Lenovo laptop wifi Solution steps - Fix lenovo z570 z580 WiFi Issues
  5.   Laravel 5.8 Datatables Tutorial With Example
  6.   jquery radio button selected event
  7.   Angularjs Form Validation Example Tutorial From Scratch
  8.   WooCommerce Get list of all product categories
  9.   Class HTML not found laravel
  10.   Angular 6 Form Validation Tutorial Example From Scratch