mytechead

Android & Wordpress Help center

Playing with wordpress categories

People often like to publish their posts under some categories, this helps them to organise better. Even this post is under Category “WordPress” 🙂

So how to get information about a category??
here is a smart and easy way.

To get the ID of a category use this :

$cat_id = get_cat_ID("category name");

To get all the information associated with this id :

$cat_id = get_cat_ID("category name");
$cat_information = get_category($cat_id);

get_category() returns an object that contains all the information related with a category. The information can be accessed like this ::

$cat_information->term_id
$cat_information->name
$cat_information->slug
$cat_information->term_group
$cat_information->term_taxonomy_id
$cat_information->taxonomy
$cat_information->description
$cat_information->parent
$cat_information->count
$cat_information->cat_ID
$cat_information->category_count
$cat_information->category_description
$cat_information->cat_name
$cat_information->category_nicename
$cat_information->category_parent

Advertisements

Single Post Navigation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: