In get_terms_to_edit(), call get_object_term_cache() before priming cache with wp_get_object_terms().

In `get_inline_data()`, do the same.

On list table screens with taxonomies in the admin, this dramatically reduces the number of database queries (3x less). Even more so with a persistent object cache (5x less).

Props johnbillion, jeffstieler, wonderboymusic.
Fixes #18968.


Built from https://develop.svn.wordpress.org/trunk@28561


git-svn-id: http://core.svn.wordpress.org/trunk@28387 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor
2014-05-23 19:29:14 +00:00
parent f50d5233f3
commit 5b5b756edf
2 changed files with 27 additions and 13 deletions

View File

@@ -364,11 +364,21 @@ function get_inline_data($post) {
$taxonomy = get_taxonomy( $taxonomy_name );
if ( $taxonomy->hierarchical && $taxonomy->show_ui ) {
echo '<div class="post_category" id="' . $taxonomy_name . '_' . $post->ID . '">'
. implode( ',', wp_get_object_terms( $post->ID, $taxonomy_name, array( 'fields' => 'ids' ) ) ) . '</div>';
$terms = get_object_term_cache( $post->ID, $taxonomy_name );
if ( false === $terms ) {
$terms = wp_get_object_terms( $post->ID, $taxonomy_name );
wp_cache_add( $post->ID, $terms, $taxonomy_name . '_relationships' );
}
$term_ids = empty( $terms ) ? array() : wp_list_pluck( $terms, 'term_id' );
echo '<div class="post_category" id="' . $taxonomy_name . '_' . $post->ID . '">' . implode( ',', $term_ids ) . '</div>';
} elseif ( $taxonomy->show_ui ) {
echo '<div class="tags_input" id="'.$taxonomy_name.'_'.$post->ID.'">'
. esc_html( str_replace( ',', ', ', get_terms_to_edit( $post->ID, $taxonomy_name ) ) ) . '</div>';
}
}