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.

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;
print_r($cat);

Web Programming Tutorials Example with Demo

Read :

  WooCommerce Get list of all product categories

Summary

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.

Leave a Reply

avatar
  Subscribe  
Notify of