# get_metadata_raw()

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

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

## Сигнатура

```php
get_metadata_raw( string $meta_type, int $object_id, string $meta_key = '', bool $single = false ): mixed
```

## Описание

Возвращает необработанное значение метаданных для указанного объекта.

## Параметры

- `$meta_type` `string` — обязательный. Тип объекта, к которому относятся метаданные. Принимает 'blog', 'post', 'comment', 'term', 'user' или любой другой тип объекта со связанной таблицей метаданных.
- `$object_id` `int` — обязательный. ID объекта, к которому относятся метаданные.
- `$meta_key` `string` — необязательный, по умолчанию `''`. Ключ метаданных. Если не указан, получаются все метаданные для указанного объекта.
- `$single` `bool` — необязательный, по умолчанию `false`. Если true, возвращается только первое значение указанного $meta_key.
  
  Этот параметр не действует, если $meta_key не указан.

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

`mixed` — $single $single $object_id $meta_type

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

Файл: `wp-includes/meta.php:628`

```php
function get_metadata_raw( $meta_type, $object_id, $meta_key = '', $single = false ) {
	if ( ! $meta_type || ! is_numeric( $object_id ) ) {
		return false;
	}

	$object_id = absint( $object_id );
	if ( ! $object_id ) {
		return false;
	}

	/**
	 * Short-circuits the return value of a meta field.
	 *
	 * The dynamic portion of the hook name, `$meta_type`, refers to the meta object type
	 * (blog, post, comment, term, user, or any other type with an associated meta table).
	 * Returning a non-null value will effectively short-circuit the function.
	 *
	 * Possible filter names include:
	 *
	 *  - `get_blog_metadata`
	 *  - `get_post_metadata`
	 *  - `get_comment_metadata`
	 *  - `get_term_metadata`
	 *  - `get_user_metadata`
	 *
	 * @since 3.1.0
	 * @since 5.5.0 Added the `$meta_type` parameter.
	 *
	 * @param mixed  $value     The value to return, either a single metadata value or an array
	 *                          of values depending on the value of `$single`. Default null.
	 * @param int    $object_id ID of the object metadata is for.
	 * @param string $meta_key  Metadata key.
	 * @param bool   $single    Whether to return only the first value of the specified `$meta_key`.
	 * @param string $meta_type Type of object metadata is for. Accepts 'blog', 'post', 'comment', 'term',
	 *                          'user', or any other object type with an associated meta table.
	 */
	$check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, $single, $meta_type );
	if ( null !== $check ) {
		if ( $single && is_array( $check ) ) {
			return $check[0];
		} else {
			return $check;
		}
	}

	$meta_cache = wp_cache_get( $object_id, $meta_type . '_meta' );

	if ( ! $meta_cache ) {
		$meta_cache = update_meta_cache( $meta_type, array( $object_id ) );
		$meta_cache = $meta_cache[ $object_id ] ?? null;
	}

	if ( ! $meta_key ) {
		return $meta_cache;
	}

	if ( isset( $meta_cache[ $meta_key ] ) ) {
		if ( $single ) {
			return maybe_unserialize( $meta_cache[ $meta_key ][0] );
		} else {
			return array_map( 'maybe_unserialize', $meta_cache[ $meta_key ] );
		}
	}

	return null;
}
```

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

- 5.5.0 — Introduced.

## Связанные

Использует: [`maybe_unserialize`](https://chugunov.pro/api-wordpress/functions/maybe_unserialize/), [`update_meta_cache`](https://chugunov.pro/api-wordpress/functions/update_meta_cache/), [`wp_cache_get`](https://chugunov.pro/api-wordpress/functions/wp_cache_get/), [`absint`](https://chugunov.pro/api-wordpress/functions/absint/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/).
Используется в: `WP_REST_Autosaves_Controller::create_post_autosave`, `WP_REST_Meta_Fields::delete_meta_value`, `WP_REST_Meta_Fields::update_multi_meta_value`, `WP_REST_Meta_Fields::update_meta_value`, [`get_metadata`](https://chugunov.pro/api-wordpress/functions/get_metadata/), [`update_metadata`](https://chugunov.pro/api-wordpress/functions/update_metadata/).

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