更新给定术语对象ID的高速缓存。

原型

update_object_term_cache( string|array $object_ids, array|string $object_type )

描述

注意:由于性能问题,应特别注意仅在必要时更新术语缓存。处理时间可以指数增加,具体取决于传递的术语ID的数量和这些术语所属的分类法的数量。

参数

$object_ids (string|array) (Required) 以逗号分隔的列表或术语对象ID数组。

$object_type (array|string) (Required) 分类对象类型。

返回值

(void|false)  如果所有条款都是假的

源文件

路径:wp-includes/taxonomy.php

<?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);
	$taxonomies = get_object_taxonomies($object_type);
	$ids = array();
	foreach ( (array) $object_ids as $id ) {
		foreach ( $taxonomies as $taxonomy ) {
			if ( false === wp_cache_get($id, "{$taxonomy}_relationships") ) {
				$ids[] = $id;
				break;
			}
		}
	}
	if ( empty( $ids ) )
		return false;
	$terms = wp_get_object_terms( $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 ( $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" );
		}
	}
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/update_object_term_cache/