If you want to get category id by using category name then use the following code

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

then Just call the function with your category name as a parameter. for example

$category_ID = get_category_id('Books');

Now you can get the category Id in variable $category_ID.

Have any doubt, then comment here!

Leave a Reply

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