On this page
get_cat_ID( string $cat_name ): int
Retrieves the ID of a category from its name.
Parameters
$cat_namestring Required-
Category name.
Return
int Category ID on success, 0 if the category doesn't exist.
Source
File: wp-includes/category.php. View all references
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;
}
Related
Uses
| Uses | Description |
|---|---|
| get_term_by() wp-includes/taxonomy.php | Gets all term data from database by term field and data. |
Used By
| Used By | Description |
|---|---|
| wp_xmlrpc_server::mw_editPost() wp-includes/class-wp-xmlrpc-server.php | Edit a post. |
| wp_xmlrpc_server::mw_newPost() wp-includes/class-wp-xmlrpc-server.php | Create a new post. |
Changelog
| Version | Description |
|---|---|
| 1.0.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_cat_id