# wp_set_post_terms()

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

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

## Сигнатура

```php
wp_set_post_terms( int $post_id, string|array $terms = '', string $taxonomy = 'post_tag', bool $append = false ): array|false|WP_Error
```

## Описание

См. alsowp_set_object_terms()

## Параметры

- `$post_id` `int` — необязательный. ID записи. Не принимает по умолчанию ID глобального объекта $post.
- `$terms` `string|array` — необязательный, по умолчанию `''`. Массив терминов для установки записи или строка терминов, разделённых запятыми. Для иерархических таксономий всегда нужно передавать ID, а не имена, чтобы не перепутать дочерние термины с одинаковыми именами, но разными родителями.
- `$taxonomy` `string` — необязательный, по умолчанию `'post_tag'`. Имя таксономии. Значение по умолчанию 'post_tag'.
- `$append` `bool` — необязательный, по умолчанию `false`. Если true, существующие термины не удаляются, а только добавляются новые. Если false, термины заменяются новыми.

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

`array|false|WP_Error` — WP_Error

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

Файл: `wp-includes/post.php:5712`

```php
function wp_set_post_terms( $post_id = 0, $terms = '', $taxonomy = 'post_tag', $append = false ) {
	$post_id = (int) $post_id;

	if ( ! $post_id ) {
		return false;
	}

	if ( empty( $terms ) ) {
		$terms = array();
	}

	if ( ! is_array( $terms ) ) {
		$comma = _x( ',', 'tag delimiter' );
		if ( ',' !== $comma ) {
			$terms = str_replace( $comma, ',', $terms );
		}
		$terms = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) );
	}

	/*
	 * Hierarchical taxonomies must always pass IDs rather than names so that
	 * children with the same names but different parents aren't confused.
	 */
	if ( is_taxonomy_hierarchical( $taxonomy ) ) {
		$terms = array_unique( array_map( 'intval', $terms ) );
	}

	return wp_set_object_terms( $post_id, $terms, $taxonomy, $append );
}
```

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

- 2.8.0 — Introduced.

## Связанные

Использует: [`wp_set_object_terms`](https://chugunov.pro/api-wordpress/functions/wp_set_object_terms/), [`is_taxonomy_hierarchical`](https://chugunov.pro/api-wordpress/functions/is_taxonomy_hierarchical/), [`_x`](https://chugunov.pro/api-wordpress/functions/_x/).
Используется в: [`wp_set_unique_slug_on_create_template_part`](https://chugunov.pro/api-wordpress/functions/wp_set_unique_slug_on_create_template_part/), [`wp_publish_post`](https://chugunov.pro/api-wordpress/functions/wp_publish_post/), [`wp_set_post_tags`](https://chugunov.pro/api-wordpress/functions/wp_set_post_tags/), [`wp_set_post_categories`](https://chugunov.pro/api-wordpress/functions/wp_set_post_categories/), [`wp_insert_post`](https://chugunov.pro/api-wordpress/functions/wp_insert_post/), [`set_post_format`](https://chugunov.pro/api-wordpress/functions/set_post_format/).

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