The output returned from get_category or get_the_category or get_categories WordPress functions is a category row object or array. For example consider the below function which can be used to get the categories of the wordpress blog satisfying some input parameters.
$arguments=array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories=get_categories($arguments);
foreach($categories as $category) {
echo $category->cat_name;
}
Thus here we get the $category WordPress object in picture.
Complete List of Fields of WordPress Category Row Object
Below is the list of the members or the fields that you get access to once you get the $category WordPress object
1. $category->cat_ID or $category->term_id
The numeric id of the category.
2. $category->cat_name or $category->name
The name that you have specified for that category, can refer in the Posts –> Categories panel in the WordPress admin
3. $category->category_nicename or $category->slug
The slug of the category, this can also be referred at in the Posts –> Categories panel in the WordPress admin
4. $category->category_description or $category->description
Category Description entered while creating or editing the category.
5. $category->category_count or $category->count
The number of posts which are put in this category. If the category is a parent category of some child category, this count represents the count of posts that belong to the parent category, the posts count for the child category is not included in this value.
6. $category->category_parent or $category->parent
The Category ID of the immediate parent category if this is a child or sub category. For example, consider this category hierarchy. Parent –> child 1 –> child 2
If the category accessed using $category object is the ‘child 2’ category, then this field will output the Category Id of the ‘child1’ category which is the immediate parent of ‘child 2’ sub-category and not of ‘Parent’
After you get the ID of the parent category you can access that parent category fields using the get_category(‘category id of the parent category’) WordPress function. This function will output the Category row object specific to the ‘child 2’ category.
7. $category->taxonomy
For categories, this value is always equal to ‘category’
8. $category->term_taxonomy_id
term_taxonomy_id is the field from the wp_term_relationships table, which binds the particular term i.e. category in this case to various objects i.e. WordPress posts (This object_id is actually populated using the post_id from the posts table). Thus term_taxonomy_id binds the categories with post, so that a relationship could be defined this post has these many categories. There are separate rows for each Object-Id (Post) –> term_taxonomy_id combination
If you liked this information, get more updates on WordPress by subscribing to our feed. Please post your inputs and repercussions thru the comments section.