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:

Discussion [Participate or Link]

  1. Abhijit Nadgouda @ iface knwsfb7v3y » Blog Archive » post_cache said:

    […] category_cache […]

  2. Abhijit Nadgouda @ iface » Blog Archive » Wordpress Global Variables said:

    […] $category_cache […]

  3. that jon jackson said:

    FINALLY! I wish i had found this site hours ago, i was trying to use: “is_category” instead of “in_category”

    UGH, what a pain.

  4. references» Blog Archive » Wordpress Global Variables said:

    […] $category_cache […]

  5. Abhijit Nadgouda’s List of WordPress Global Variables « Lorelle on WordPress said:

    […] max_num_pages, numpages, page, pages, multipage, paged, post, id, authordata, post_cache, category_cache, and […]

Say your thought!

If you want to use HTML you can use these tags: <a>, <em>, <strong>, <abbr>, <code>, <blockquote>. Closing the tags will be appreciated as this site uses valid XHTML.



Abhijit Nadgouda
iface Consulting
+91 9819820312
My bookmarks


This is the weblog of Abhijit Nadgouda where he writes down his thoughts on software development and related topics. You are invited to subscribe to the feed to stay updated or check out more subscription options. Or you can choose to browse by one of the topics.