WordPress at a glance

get_cat_ID() WP 1.0

Retrieve the ID of a category from its name.

Works based on: get_term_by()

No Hooks.

Return

Int. Category ID on success, 0 if the category doesn't exist.

Usage

get_cat_ID( $cat_name ) // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid;
$cat_name(string) (required)
Category name.

Changelog

Since 1.0.0 Introduced.

Code of get_cat_ID() WP 5.5.3

<?php
function get_cat_ID( $cat_name ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
	$cat = get_term_by( 'name', $cat_name, 'category' );

	if ( $cat ) {
		return $cat->term_id;
	}

	return 0;
}

From category: Categories

No comments
    Log In . Register