Just like category_cache, WordPress uses post_cache global variable to cache all the posts by their IDs. It is set in the function update_post_caches($posts) defined in [wordpress root folder]/wp-includes/functions.php. post_cache is an array and indexes post by the post ID. WordPress provides function clean_post_cache($id) to cleanup or unset the post for the specified ID.

post_cache is internally used by WordPress in following functions:

  • get_posts($args): codex document
  • get_children($post = 0, $output = OBJECT): returns child posts of the specified post. If not post is specified, children of current post are returned. This is specifically useful when retrieving heirarchical static pages.

Plugin and theme developers can use the cache when retrieving the entire posts or individual fields. They can also use update_post_caches($posts) to update the cache. This function also updates the category cache using update_post_category_cache($post_ids).

Technorati tags: , , .

Discussion [Participate or Link]

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

    […] $post_cache […]

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

    […] Post and Page Variables: wp_query, posts, more, posts_per_page, max_num_pages, numpages, page, pages, multipage, paged, post, id, authordata, post_cache, category_cache, and post_meta_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.



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.