Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get category


Retrieves category data given a category ID or category object.

If you pass the $category parameter an object, which is assumed to be the category row object retrieved the database. It will cache the category data.

If you pass $category an integer of the category ID, then that category will be retrieved from the database, if it isn't already cached, and pass it back.

If you look at get_term(), then both types will be passed through several filters and finally sanitized based on the $filter parameter value.

The category will converted to maintain backwards compatibility.

Note: use get_term() to get Link Categories based on their ID's. get_category only returns Post Categories.


<?php get_category$category$output$filter ?>


(integer|object) (required) Category ID or Category row object
Default: None
(string) (optional) Constant OBJECT, ARRAY_A, or ARRAY_N
Default: OBJECT
(string) (optional) Default is raw or no WordPress defined filter will applied.
Default: 'raw'

Return Values

Category data in type defined by $output parameter. Returns null if $category does not exist.


Sample get_category() code

<?php $thisCat get_category(get_query_var('cat')); ?>

The variable $thisCat is now:

stdClass Object
    [term_id] => 85
    [name] => Category Name
    [slug] => category-name
    [term_group] => 0
    [term_taxonomy_id] => 85
    [taxonomy] => category
    [description] => 
    [parent] => 70
    [count] => 0
    [cat_ID] => 85
    [category_count] => 0
    [category_description] => 
    [cat_name] => Category Name
    [category_nicename] => category-name
    [category_parent] => 70


  • Uses: get_term() Used to get the category data from the taxonomy.
  • The count attribute includes custom post types as well if the custom post type uses standard categories.

Change Log

Source File

get_category() is located in wp-includes/category.php.


See also index of Function Reference and index of Template Tags.