wpseek.com
Outil de recherche WordPress pour les développeurs et auteurs de thèmes



get_the_category_by_id › WordPress Function

Depuis0.71
Dépréciéen/a
get_the_category_by_id ( $cat_id )
Paramètres:
  • (int) $cat_id Category ID.
    Requis: Oui
Retourne:
  • (string|WP_Error) Category name on success, WP_Error on failure.
Défini(e) dans:
Codex:

Retrieves category name based on category ID.



Source

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 : '';
}