On this page
get_the_category_by_ID( int $cat_id ): string|WP_Error
Retrieves category name based on category ID.
Parameters
$cat_idint Required-
Category ID.
Return
string|WP_Error Category name on success, WP_Error on failure.
Source
File: wp-includes/category-template.php. View all references
function get_the_category_by_ID( $cat_id ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
$cat_id = (int) $cat_id;
$category = get_term( $cat_id );
if ( is_wp_error( $category ) ) {
return $category;
}
return ( $category ) ? $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 |
|---|---|
| the_category_head() wp-includes/deprecated.php | Prints a category with optional text before and after. |
Changelog
| Version | Description |
|---|---|
| 0.71 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_the_category_by_id