Source
File: wp-includes/taxonomy.php
function update_object_term_cache( $object_ids, $object_type ) {
if ( empty( $object_ids ) ) {
return;
}
if ( ! is_array( $object_ids ) ) {
$object_ids = explode( ',', $object_ids );
}
$object_ids = array_map( 'intval', $object_ids );
$non_cached_ids = array();
$taxonomies = get_object_taxonomies( $object_type );
foreach ( $taxonomies as $taxonomy ) {
$cache_values = wp_cache_get_multiple( (array) $object_ids, "{$taxonomy}_relationships" );
foreach ( $cache_values as $id => $value ) {
if ( false === $value ) {
$non_cached_ids[] = $id;
}
}
}
if ( empty( $non_cached_ids ) ) {
return false;
}
$non_cached_ids = array_unique( $non_cached_ids );
$terms = wp_get_object_terms(
$non_cached_ids,
$taxonomies,
array(
'fields' => 'all_with_object_id',
'orderby' => 'name',
'update_term_meta_cache' => false,
)
);
$object_terms = array();
foreach ( (array) $terms as $term ) {
$object_terms[ $term->object_id ][ $term->taxonomy ][] = $term->term_id;
}
foreach ( $non_cached_ids as $id ) {
foreach ( $taxonomies as $taxonomy ) {
if ( ! isset( $object_terms[ $id ][ $taxonomy ] ) ) {
if ( ! isset( $object_terms[ $id ] ) ) {
$object_terms[ $id ] = array();
}
$object_terms[ $id ][ $taxonomy ] = array();
}
}
}
foreach ( $object_terms as $id => $value ) {
foreach ( $value as $taxonomy => $terms ) {
wp_cache_add( $id, $terms, "{$taxonomy}_relationships" );
}
}
}