WordPress uses category_cache global variable to cache categories by posts. This means that it can be queried for categories by providing the post ID. It is a two-dimensional array set in the function update_post_category_cache($post_ids) defined in [wordpress root folder]/wp-includes/functions.php.

The cache can improve performance by saving repeated trips to the database for querying the same data.

WordPress uses category_cache internally in the following functions:

  • get_the_category($post_id = false): returns categories the specified post is classified under. An array of the categories is returned.
  • in_category($category): tells whether the current post is in the specified category or not.

Back to full list of global variables.

Technorati tags:

2 Responses to “category_cache”

Leave a Reply

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

You are commenting using your 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: