Posted inTechnology / php / Programming / wordpress

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 :

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.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

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

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype