Opened 15 years ago
Closed 15 years ago
#12989 closed defect (bug) (fixed)
Object term cache not updated for custom post types
Reported by: | greenshady | Owned by: | ryan |
---|---|---|---|
Milestone: | 3.0 | Priority: | normal |
Severity: | normal | Version: | 3.0 |
Component: | Cache API | Keywords: | has-patch dev-reviewed |
Focuses: | Cc: |
Description
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.
When WP_Query::get_posts() calls update_post_caches() it should probably pass along the post type. update_post_caches() would need to know how to handle multiple post type queries and the 'any' post type (perhaps just not try to cache those). Attached is an untested start on a patch.