[wp-trac] [WordPress Trac] #12989: Object term cache not updated for custom post types

WordPress Trac wp-trac at lists.automattic.com
Tue Apr 13 20:44:48 UTC 2010


#12989: Object term cache not updated for custom post types
--------------------------+-------------------------------------------------
 Reporter:  greenshady    |       Owner:  ryan
     Type:  defect (bug)  |      Status:  new 
 Priority:  normal        |   Milestone:  3.0 
Component:  Cache         |     Version:  3.0 
 Severity:  normal        |    Keywords:      
--------------------------+-------------------------------------------------
 I was tinkering around with custom post types with their own custom
 taxonomies today and realized I had a page with 70+ database queries and
 only 10 "posts" listed, each with 5 term lists.  This was with running
 file-based caching, so I knew something was wrong.

 The problem seemed to be coming from calls to `get_the_term_list()` for
 the custom taxonomies.  Each time this was called, it was querying the
 database.  This wouldn't be so bad if we were simply listing 10 "posts",
 each with one call to the `get_the_term_list()`.

 `get_the_term_list()` calls `get_the_terms()`, which checks for the object
 term cache like so:

 {{{
 $terms = get_object_term_cache( $id, $taxonomy );
 }}}

 Unfortunately, with custom post types, this ALWAYS returns false.  So, the
 function must get this information from the database.

 After some more digging, I found my way to the `update_post_caches()`
 function in `wp-includes/post.php`, which is where I think the problem is.
 It explicitly says the object type is `post`:

 {{{
 update_object_term_cache($post_ids, 'post');
 }}}

 Making a quick change of `post` to `ticket` (my custom post type) and a
 page refresh fixed my database query issue.

 I may be off base about where the problem originates but this seems to be
 it.  I tried to dig as deep as I could on this one and provide the
 necessary steps.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/12989>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list