On this page
get_cat_name( int $cat_id ): string
Retrieves the name of a category from its ID.
Parameters
$cat_idint Required-
Category ID.
Return
string Category name, or an empty string if the category doesn't exist.
Source
File: wp-includes/category.php. View all references
function get_cat_name( $cat_id ) {
$cat_id = (int) $cat_id;
$category = get_term( $cat_id, 'category' );
if ( ! $category || is_wp_error( $category ) ) {
return '';
}
return $category->name;
}
Related
Uses
| Uses | Description |
|---|---|
| get_term() wp-includes/taxonomy.php | Gets all term data from database by term ID. |
| is_wp_error() wp-includes/load.php | Checks whether the given variable is a WordPress Error. |
Used By
| Used By | Description |
|---|---|
| get_catname() wp-includes/deprecated.php | Retrieve the category name by the category ID. |
| wp_xmlrpc_server::mt_getPostCategories() wp-includes/class-wp-xmlrpc-server.php | Retrieve post categories. |
| wp_xmlrpc_server::mw_getPost() wp-includes/class-wp-xmlrpc-server.php | Retrieve post. |
| wp_xmlrpc_server::mw_getRecentPosts() wp-includes/class-wp-xmlrpc-server.php | Retrieve list of recent posts. |
| wp_xmlrpc_server::_prepare_page() wp-includes/class-wp-xmlrpc-server.php | Prepares page data for return in an XML-RPC object. |
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_name