ifacethoughts

category_cache

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.
    thanks.
    bye
    jon

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

    [...] $category_cache [...]

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.

freshthoughts

contactme

Abhijit Nadgouda
iface Consulting
India
+91 9819820312
My bookmarks

badgesand...

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.