WordPress.org

Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#14821 closed enhancement (duplicate)

Add multiple post type support to update_object_term_cache()

Reported by: johnbillion Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0.1
Component: Performance Keywords: has-patch
Focuses: Cc:
PR Number:

Description

update_object_term_cache() only accepts one post_type. If a loop contains more than one post type then the object term cache isn't populated and your queries can go through the roof.

See http://lists.automattic.com/pipermail/wp-hackers/2010-September/034776.html

Patch coming up.

Attachments (2)

14821.patch (961 bytes) - added by johnbillion 9 years ago.
14821.2.patch (1.7 KB) - added by johnbillion 9 years ago.

Download all attachments as: .zip

Change History (7)

@johnbillion
9 years ago

#1 @johnbillion
9 years ago

  • Keywords has-patch added

Patch.

This patch changes update_post_caches() so it calls update_object_term_cache() for each post type in the $posts array if the $post_type parameter isn't set or it's set to 'any'.

#2 @nacin
9 years ago

We should probably adjust update_object_term_cache() to accept multiple post types instead, that way we still keep to a single wp_get_object_terms() call.

Support for it should probably be pretty easy. Simply call get_object_taxonomies() for each post type and merge the result, I think.

#3 @nacin
9 years ago

  • Milestone changed from Awaiting Review to 3.1

@johnbillion
9 years ago

#4 @johnbillion
9 years ago

That does indeed work.

Updated patch changes update_object_term_cache() so it accepts a single object type or an array of object types.

update_post_caches() is also modified so it passes an array of the post types from the $posts array if $post_type is set to 'all'.

#5 @nacin
9 years ago

  • Milestone 3.1 deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Turns out get_object_taxonomies() can handle an array. I honestly hadn't checked originally, sorry about that. Closing as a duplicate of #15026, now fixed.

Note: See TracTickets for help on using tickets.