# get_object_term_cache()

URL: https://chugunov.pro/api-wordpress/functions/get_object_term_cache/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 2.3.0.

## Сигнатура

```php
get_object_term_cache( int $id, string $taxonomy ): bool|WP_Term[]|WP_Error
```

## Описание

Вышестоящие функции (такие как get_the_terms() и is_object_in_term()) отвечают за заполнение кеша связей объектов с терминами. Эта функция извлекает только те данные о связях, которые уже находятся в кеше.

## Параметры

- `$id` `int` — обязательный. ID объекта термина, например ID записи, комментария или пользователя.
- `$taxonomy` `string` — обязательный. Имя таксономии.

## Возвращаемое значение

`bool|WP_Term[]|WP_Error` — WP_Term $taxonomy $id WP_Error get_term()

## Исходный код

Файл: `wp-includes/taxonomy.php:3771`

```php
function get_object_term_cache( $id, $taxonomy ) {
	$_term_ids = wp_cache_get( $id, "{$taxonomy}_relationships" );

	// We leave the priming of relationship caches to upstream functions.
	if ( false === $_term_ids ) {
		return false;
	}

	// Backward compatibility for if a plugin is putting objects into the cache, rather than IDs.
	$term_ids = array();
	foreach ( $_term_ids as $term_id ) {
		if ( is_numeric( $term_id ) ) {
			$term_ids[] = (int) $term_id;
		} elseif ( isset( $term_id->term_id ) ) {
			$term_ids[] = (int) $term_id->term_id;
		}
	}

	// Fill the term objects.
	_prime_term_caches( $term_ids );

	$terms = array();
	foreach ( $term_ids as $term_id ) {
		$term = get_term( $term_id, $taxonomy );
		if ( is_wp_error( $term ) ) {
			return $term;
		}

		$terms[] = $term;
	}

	return $terms;
}
```

## История изменений

- 4.7.0 — Returns a WP_Error object if there’s an error with any of the matched terms.
- 2.3.0 — Introduced.

## Связанные

Использует: [`_prime_term_caches`](https://chugunov.pro/api-wordpress/functions/_prime_term_caches/), [`wp_cache_get`](https://chugunov.pro/api-wordpress/functions/wp_cache_get/), [`get_term`](https://chugunov.pro/api-wordpress/functions/get_term/), [`is_wp_error`](https://chugunov.pro/api-wordpress/functions/is_wp_error/).
Используется в: [`get_terms_to_edit`](https://chugunov.pro/api-wordpress/functions/get_terms_to_edit/), [`get_inline_data`](https://chugunov.pro/api-wordpress/functions/get_inline_data/), [`get_attachment_fields_to_edit`](https://chugunov.pro/api-wordpress/functions/get_attachment_fields_to_edit/), [`get_compat_media_markup`](https://chugunov.pro/api-wordpress/functions/get_compat_media_markup/), [`get_the_terms`](https://chugunov.pro/api-wordpress/functions/get_the_terms/), [`get_the_taxonomies`](https://chugunov.pro/api-wordpress/functions/get_the_taxonomies/), [`is_object_in_term`](https://chugunov.pro/api-wordpress/functions/is_object_in_term/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/get_object_term_cache/
