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:  Same Scope Variable in Multiple Controllers using Angular 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 :

Read Also:  Angularjs Table Pagination Example with Code

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.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  how to get product category in woocommerce?
  2. Read Also:  Calculate Date Difference using jquery Example
  3. Read Also:  How to Compare Date in SQL Server Query?
  4. Read Also:  JavaScript Remove Item From Comma Separated string
  5. Read Also:  WooCommerce Get list of all product categories
  6. Read Also:  How to check if string contains substring in PHP?
  7. Read Also:  how to Text area Set Max Length And Char Count With JavaScript
  8. Read Also:  Bash if else Statment
  9. Read Also:  Vue check v-if Array object is Empty/isset/Null
  10. Read Also:  Laravel 6 Ajax post data Example
CLOSEX