# wp_get_object_terms()

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

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

## Сигнатура

```php
wp_get_object_terms( int|int[] $object_ids, string|string[] $taxonomies, array|string $args = array() ): WP_Term[]|int[]|string[]|string|WP_Error
```

## Описание

Получает термины, связанные с заданным объектом(ами), в указанных таксономиях.

## Параметры

- `$object_ids` `int|int[]` — обязательный. ID объекта(ов) для получения.
- `$taxonomies` `string|string[]` — обязательный. Имена таксономий, из которых нужно получить термины.
- `$args` `array|string` — необязательный, по умолчанию `array()`. See [WP_Term_Query::__construct()](https://developer.wordpress.org/reference/classes/wp_term_query/__construct/) for supported arguments.

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

`WP_Term[]|int[]|string[]|string|WP_Error` — WP_Error WP_Term_Query::__TOKEN_1__

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

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

```php
function wp_get_object_terms( $object_ids, $taxonomies, $args = array() ) {
	if ( empty( $object_ids ) || empty( $taxonomies ) ) {
		return array();
	}

	if ( ! is_array( $taxonomies ) ) {
		$taxonomies = array( $taxonomies );
	}

	foreach ( $taxonomies as $taxonomy ) {
		if ( ! taxonomy_exists( $taxonomy ) ) {
			return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) );
		}
	}

	if ( ! is_array( $object_ids ) ) {
		$object_ids = array( $object_ids );
	}
	$object_ids = array_map( 'intval', $object_ids );

	$defaults = array(
		'update_term_meta_cache' => false,
	);

	$args = wp_parse_args( $args, $defaults );

	/**
	 * Filters arguments for retrieving object terms.
	 *
	 * @since 4.9.0
	 *
	 * @param array    $args       An array of arguments for retrieving terms for the given object(s).
	 *                             See wp_get_object_terms() for details.
	 * @param int[]    $object_ids Array of object IDs.
	 * @param string[] $taxonomies Array of taxonomy names to retrieve terms from.
	 */
	$args = apply_filters( 'wp_get_object_terms_args', $args, $object_ids, $taxonomies );

	/*
	 * When one or more queried taxonomies is registered with an 'args' array,
	 * those params override the `$args` passed to this function.
	 */
	$terms = array();
	if ( count( $taxonomies ) > 1 ) {
		foreach ( $taxonomies as $index => $taxonomy ) {
			$t = get_taxonomy( $taxonomy );
			if ( isset( $t->args ) && is_array( $t->args ) && array_merge( $args, $t->args ) != $args ) {
				unset( $taxonomies[ $index ] );
				$terms = array_merge( $terms, wp_get_object_terms( $object_ids, $taxonomy, array_merge( $args, $t->args ) ) );
			}
		}
	} else {
		$t = get_taxonomy( $taxonomies[0] );
		if ( isset( $t->args ) && is_array( $t->args ) ) {
			$args = array_merge( $args, $t->args );
		}
	}

	$args['taxonomy']   = $taxonomies;
	$args['object_ids'] = $object_ids;

	// Taxonomies registered without an 'args' param are handled here.
	if ( ! empty( $taxonomies ) ) {
		$terms_from_remaining_taxonomies = get_terms( $args );

		// Array keys should be preserved for values of $fields that use term_id for keys.
		if ( ! empty( $args['fields'] ) && str_starts_with( $args['fields'], 'id=>' ) ) {
			$terms = $terms + $terms_from_remaining_taxonomies;
		} else {
			$terms = array_merge( $terms, $terms_from_remaining_taxonomies );
		}
	}

	/**
	 * Filters the terms for a given object or objects.
	 *
	 * @since 4.2.0
	 *
	 * @param WP_Term[]|int[]|string[]|string $terms      Array of terms or a count thereof as a numeric string.
	 * @param int[]                           $object_ids Array of object IDs for which terms were retrieved.
	 * @param string[]                        $taxonomies Array of taxonomy names from which terms were retrieved.
	 * @param array                           $args       Array of arguments for retrieving terms for the given
	 *                                                    object(s). See wp_get_object_terms() for details.
	 */
	$terms = apply_filters( 'get_object_terms', $terms, $object_ids, $taxonomies, $args );

	$object_ids = implode( ',', $object_ids );
	$taxonomies = "'" . implode( "', '", array_map( 'esc_sql', $taxonomies ) ) . "'";

	/**
	 * Filters the terms for a given object or objects.
	 *
	 * The `$taxonomies` parameter passed to this filter is formatted as a SQL fragment. The
	 * 'get_object_terms' filter is recommended as an alternative.
	 *
	 * @since 2.8.0
	 *
	 * @param WP_Term[]|int[]|string[]|string $terms      Array of terms or a count thereof as a numeric string.
	 * @param string                          $object_ids Comma separated list of object IDs for which terms were retrieved.
	 * @param string                          $taxonomies SQL fragment of taxonomy names from which terms were retrieved.
	 * @param array                           $args       Array of arguments for retrieving terms for the given
	 *                                                    object(s). See wp_get_object_terms() for details.
	 */
	return apply_filters( 'wp_get_object_terms', $terms, $object_ids, $taxonomies, $args );
}
```

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

- 6.3.0 — Passing update_term_meta_cache argument value false by default resulting in get_terms() to not prime the term meta cache.
- 4.7.0 — Refactored to use WP_Term_Query, and to support any WP_Term_Query arguments.
- 4.4.0 — Introduced $meta_query and $update_term_meta_cache arguments. When $fields is 'all' or 'all_with_object_id', an array of WP_Term objects will be returned.
- 4.2.0 — Added support for 'taxonomy', 'parent', and 'term_taxonomy_id' values of $orderby. Introduced $parent argument.
- 2.3.0 — Introduced.

## Связанные

Использует: [`wp_get_object_terms`](https://chugunov.pro/api-wordpress/functions/wp_get_object_terms/), [`get_terms`](https://chugunov.pro/api-wordpress/functions/get_terms/), [`taxonomy_exists`](https://chugunov.pro/api-wordpress/functions/taxonomy_exists/), [`__`](https://chugunov.pro/api-wordpress/functions/__/), [`wp_parse_args`](https://chugunov.pro/api-wordpress/functions/wp_parse_args/), [`get_taxonomy`](https://chugunov.pro/api-wordpress/functions/get_taxonomy/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/), `WP_Error::__construct`.
Используется в: `WP_REST_Terms_Controller::get_items`, [`wxr_post_taxonomy`](https://chugunov.pro/api-wordpress/functions/wxr_post_taxonomy/), [`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/), [`wp_terms_checklist`](https://chugunov.pro/api-wordpress/functions/wp_terms_checklist/), [`wp_popular_terms_checklist`](https://chugunov.pro/api-wordpress/functions/wp_popular_terms_checklist/), [`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/), [`bulk_edit_posts`](https://chugunov.pro/api-wordpress/functions/bulk_edit_posts/), [`wp_get_link_cats`](https://chugunov.pro/api-wordpress/functions/wp_get_link_cats/), [`get_the_terms`](https://chugunov.pro/api-wordpress/functions/get_the_terms/), [`update_object_term_cache`](https://chugunov.pro/api-wordpress/functions/update_object_term_cache/), [`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/), [`wp_get_object_terms`](https://chugunov.pro/api-wordpress/functions/wp_get_object_terms/), [`wp_set_object_terms`](https://chugunov.pro/api-wordpress/functions/wp_set_object_terms/), [`wp_delete_object_term_relationships`](https://chugunov.pro/api-wordpress/functions/wp_delete_object_term_relationships/), [`wp_delete_term`](https://chugunov.pro/api-wordpress/functions/wp_delete_term/), [`get_adjacent_post`](https://chugunov.pro/api-wordpress/functions/get_adjacent_post/), [`get_boundary_post`](https://chugunov.pro/api-wordpress/functions/get_boundary_post/), [`_wp_menu_item_classes_by_context`](https://chugunov.pro/api-wordpress/functions/_wp_menu_item_classes_by_context/), [`_update_term_count_on_transition_post_status`](https://chugunov.pro/api-wordpress/functions/_update_term_count_on_transition_post_status/), [`wp_get_post_categories`](https://chugunov.pro/api-wordpress/functions/wp_get_post_categories/), [`wp_get_post_terms`](https://chugunov.pro/api-wordpress/functions/wp_get_post_terms/), [`wp_insert_post`](https://chugunov.pro/api-wordpress/functions/wp_insert_post/), [`get_bookmark`](https://chugunov.pro/api-wordpress/functions/get_bookmark/), `wp_xmlrpc_server::_prepare_post`.

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