WordPress at a glance

get_the_category() WP 1.0

Retrieve post categories.

This tag may be used outside The Loop by passing a post id as the parameter.

Note: This function only returns results from the default "category" taxonomy. For custom taxonomies use get_the_terms().

Is the basis for: get_the_category_list()
Works based on: get_the_terms()
Hooks from the function

WP_Term[]. Array of WP_Term objects, one for each category assigned to the post.


get_the_category( $id );
The post ID.
Default: current post ID


Since 0.71 Introduced.

Code of get the category: wp-includes/category-template.php WP 5.4.1

function get_the_category( $id = false ) {
	$categories = get_the_terms( $id, 'category' );
	if ( ! $categories || is_wp_error( $categories ) ) {
		$categories = array();

	$categories = array_values( $categories );

	foreach ( array_keys( $categories ) as $key ) {
		_make_cat_compat( $categories[ $key ] );

	 * Filters the array of categories to return for a post.
	 * @since 3.1.0
	 * @since 4.4.0 Added `$id` parameter.
	 * @param WP_Term[] $categories An array of categories to return for the post.
	 * @param int|false $id         ID of the post.
	return apply_filters( 'get_the_categories', $categories, $id );

Related Functions

From category: For posts

No comments
        Log In . Register