# get_terms()

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

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

## Сигнатура

```php
get_terms( array|string $args = array(), array|string $deprecated = '' ): WP_Term[]|int[]|string[]|string|WP_Error
```

## Описание

You can fully inject any customizations to the query before it is sent, as well as control the output with a filter.

The return type varies depending on the value passed to `$args['fields']`. See [WP_Term_Query::get_terms()](https://developer.wordpress.org/reference/classes/wp_term_query/get_terms/) for details. In all cases, a `WP_Error` object will be returned if an invalid taxonomy is requested.

The [‘get_terms’](https://developer.wordpress.org/reference/hooks/get_terms/) filter will be called when the cache has the term and will pass the found term along with the array of $taxonomies and array of $args.
This filter is also called before the array of terms is passed and will pass the array of terms, along with the $taxonomies and $args.

The [‘list_terms_exclusions’](https://developer.wordpress.org/reference/hooks/list_terms_exclusions/) filter passes the compiled exclusions along with the $args.

The [‘get_terms_orderby’](https://developer.wordpress.org/reference/hooks/get_terms_orderby/) filter passes the `ORDER BY` clause for the query along with the $args array.

Taxonomy or an array of taxonomies should be passed via the ‘taxonomy’ argument in the `$args` array:

```
$terms = get_terms( array(
'taxonomy' => 'post_tag',
'hide_empty' => false,
) );
```

Prior to 4.5.0, taxonomy was passed as the first parameter of `get_terms()`.

{@internal The `$deprecated` parameter is parsed for backward compatibility only.}

## Параметры

- `$args` `array|string` — необязательный, по умолчанию `array()`. Array or string of arguments. See [WP_Term_Query::__construct()](https://developer.wordpress.org/reference/classes/wp_term_query/__construct/) for information on accepted arguments.
- `$deprecated` `array|string` — необязательный, по умолчанию `''`. Массив аргументов при использовании устаревшего формата параметров функции.
  
  Если присутствует, этот параметр будет интерпретирован как $args, а первый параметр функции будет разобран как таксономия или массив таксономий.

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

`WP_Term[]|int[]|string[]|string|WP_Error` — WP_Error

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

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

```php
function get_terms( $args = array(), $deprecated = '' ) {
	$term_query = new WP_Term_Query();

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

	/*
	 * Legacy argument format ($taxonomy, $args) takes precedence.
	 *
	 * We detect legacy argument format by checking if
	 * (a) a second non-empty parameter is passed, or
	 * (b) the first parameter shares no keys with the default array (ie, it's a list of taxonomies)
	 */
	$_args          = wp_parse_args( $args );
	$key_intersect  = array_intersect_key( $term_query->query_var_defaults, (array) $_args );
	$do_legacy_args = $deprecated || empty( $key_intersect );

	if ( $do_legacy_args ) {
		$taxonomies       = (array) $args;
		$args             = wp_parse_args( $deprecated, $defaults );
		$args['taxonomy'] = $taxonomies;
	} else {
		$args = wp_parse_args( $args, $defaults );
		if ( isset( $args['taxonomy'] ) ) {
			$args['taxonomy'] = (array) $args['taxonomy'];
		}
	}

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

	// Don't pass suppress_filter to WP_Term_Query.
	$suppress_filter = $args['suppress_filter'];
	unset( $args['suppress_filter'] );

	$terms = $term_query->query( $args );

	// Count queries are not filtered, for legacy reasons.
	if ( ! is_array( $terms ) ) {
		return $terms;
	}

	if ( $suppress_filter ) {
		return $terms;
	}

	/**
	 * Filters the found terms.
	 *
	 * @since 2.3.0
	 * @since 4.6.0 Added the `$term_query` parameter.
	 *
	 * @param array         $terms      Array of found terms.
	 * @param array|null    $taxonomies An array of taxonomies if known.
	 * @param array         $args       An array of get_terms() arguments.
	 * @param WP_Term_Query $term_query The WP_Term_Query object.
	 */
	return apply_filters( 'get_terms', $terms, $term_query->query_vars['taxonomy'], $term_query->query_vars, $term_query );
}
```

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

- 4.8.0 — Introduced 'suppress_filter' parameter.
- 4.5.0 — Changed the function signature so that the $args array can be provided as the first parameter. Introduced 'meta_key' and 'meta_value' parameters. Introduced the ability to order results by metadata.
- 4.4.0 — Introduced the ability to pass 'term_id' as an alias of 'id' for the orderby parameter. Introduced the 'meta_query' and 'update_term_meta_cache' parameters. Converted to return a list of WP_Term objects.
- 4.2.0 — Introduced 'name' and 'childless' parameters.
- 2.3.0 — Introduced.

## Связанные

Использует: `WP_Term_Query::__construct`, [`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/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/), `WP_Error::__construct`.
Используется в: `WP_Posts_List_Table::formats_dropdown`, [`taxonomy_meta_box_sanitize_cb_input`](https://chugunov.pro/api-wordpress/functions/taxonomy_meta_box_sanitize_cb_input/), `WP_REST_Terms_Controller::get_items`, `WP_Term_Query::get_terms`, `WP_Customize_Nav_Menus::search_available_items_query`, `WP_Customize_Nav_Menus::load_available_items_query`, [`export_wp`](https://chugunov.pro/api-wordpress/functions/export_wp/), [`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/), [`wp_link_category_checklist`](https://chugunov.pro/api-wordpress/functions/wp_link_category_checklist/), [`wp_ajax_get_tagcloud`](https://chugunov.pro/api-wordpress/functions/wp_ajax_get_tagcloud/), [`wp_ajax_ajax_tag_search`](https://chugunov.pro/api-wordpress/functions/wp_ajax_ajax_tag_search/), `WP_Terms_List_Table::prepare_items`, [`_wp_ajax_menu_quick_search`](https://chugunov.pro/api-wordpress/functions/_wp_ajax_menu_quick_search/), [`wp_nav_menu_item_taxonomy_meta_box`](https://chugunov.pro/api-wordpress/functions/wp_nav_menu_item_taxonomy_meta_box/), `Walker_Category::start_el`, [`wp_tag_cloud`](https://chugunov.pro/api-wordpress/functions/wp_tag_cloud/), [`wp_dropdown_categories`](https://chugunov.pro/api-wordpress/functions/wp_dropdown_categories/), [`get_tags`](https://chugunov.pro/api-wordpress/functions/get_tags/), [`get_categories`](https://chugunov.pro/api-wordpress/functions/get_categories/), [`get_category_by_path`](https://chugunov.pro/api-wordpress/functions/get_category_by_path/), [`get_all_category_ids`](https://chugunov.pro/api-wordpress/functions/get_all_category_ids/), `WP_Widget_Links::form`, [`_get_term_hierarchy`](https://chugunov.pro/api-wordpress/functions/_get_term_hierarchy/), [`wp_get_object_terms`](https://chugunov.pro/api-wordpress/functions/wp_get_object_terms/), [`wp_insert_term`](https://chugunov.pro/api-wordpress/functions/wp_insert_term/), [`wp_count_terms`](https://chugunov.pro/api-wordpress/functions/wp_count_terms/), [`get_term_by`](https://chugunov.pro/api-wordpress/functions/get_term_by/), [`term_exists`](https://chugunov.pro/api-wordpress/functions/term_exists/), [`wp_list_bookmarks`](https://chugunov.pro/api-wordpress/functions/wp_list_bookmarks/), [`wp_get_nav_menus`](https://chugunov.pro/api-wordpress/functions/wp_get_nav_menus/), `wp_xmlrpc_server::wp_getTerms`, `wp_xmlrpc_server::_insert_post`.

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