Home » Simple 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.

Read Also:  github login command line

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 :

Read Also:  How to Create AngularJS UI-Grid Editable - GridView


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 infinityknow.com 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. Read Also:  Generate PDF Files using Laravel 5.7 Dynamically Scripts
  2. Read Also:  Laravel Delete Record using jquery Ajax Request
  3. Read Also:  Laravel INSERT Multiple Rows Into a Table
  4. Read Also:  jQuery AJAX login and registration Form using PHP MySQLi
  5. Read Also:  Insert JSON data MySQL
  6. Read Also:  WooCommerce Get list of all product categories
  7. Read Also:  .htaccess Redirect old domain to new domain with URL match
  8. Read Also:  json to array php
  9. Read Also:  Magento 2 How to solve one or more indexers with Reindexing using Command
  10. Read Also:  Insert JSON data MySQL

Leave a Comment

Your email address will not be published. Required fields are marked *