Title: get_metadata_raw
Published: August 11, 2020
Last modified: February 24, 2026

---

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

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/get_metadata_raw/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_metadata_raw/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_metadata_raw/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/get_metadata_raw/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/get_metadata_raw/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_metadata_raw/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/get_metadata_raw/?output_format=md#wp--skip-link--target)

Retrieves raw metadata value for the specified object.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_metadata_raw/?output_format=md#parameters)󠁿

 `$meta_type`stringrequired

Type of object metadata is for. Accepts `'blog'`, `'post'`, `'comment'`, `'term'`,`'
user'`, or any other object type with an associated meta table.

`$object_id`intrequired

ID of the object metadata is for.

`$meta_key`stringoptional

Metadata key. If not specified, retrieve all metadata for the specified object. 
Default empty string.

`$single`booloptional

If true, return only the first value of the specified `$meta_key`.
 This parameter
has no effect if `$meta_key` is not specified.

Default:`false`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_metadata_raw/?output_format=md#return)󠁿

 mixed An array of values if `$single` is false.
 The value of the meta field if`
$single` is true. False for an invalid `$object_id` (non-numeric, zero, or negative
value), or if `$meta_type` is not specified. Null if the value does not exist.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_metadata_raw/?output_format=md#source)󠁿

    ```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 ) );
    		if ( isset( $meta_cache[ $object_id ] ) ) {
    			$meta_cache = $meta_cache[ $object_id ];
    		} else {
    			$meta_cache = 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;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/meta.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/meta.php#L628)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/meta.php#L628-L697)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/get_metadata_raw/?output_format=md#hooks)󠁿

 [apply_filters( “get_{$meta_type}_metadata”, mixed $value, int $object_id, string $meta_key, bool $single, string $meta_type )](https://developer.wordpress.org/reference/hooks/get_meta_type_metadata/)

Short-circuits the return value of a meta field.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_metadata_raw/?output_format=md#related)󠁿

| Uses | Description | 
| [maybe_unserialize()](https://developer.wordpress.org/reference/functions/maybe_unserialize/)`wp-includes/functions.php` |

Unserializes data only if it was serialized.

  | 
| [update_meta_cache()](https://developer.wordpress.org/reference/functions/update_meta_cache/)`wp-includes/meta.php` |

Updates the metadata cache for the specified objects.

  | 
| [wp_cache_get()](https://developer.wordpress.org/reference/functions/wp_cache_get/)`wp-includes/cache.php` |

Retrieves the cache contents from the cache by key and group.

  | 
| [absint()](https://developer.wordpress.org/reference/functions/absint/)`wp-includes/load.php` |

Converts a value to non-negative integer.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

[Show 3 more](https://developer.wordpress.org/reference/functions/get_metadata_raw/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_metadata_raw/?output_format=md#)

| Used by | Description | 
| [WP_REST_Autosaves_Controller::create_post_autosave()](https://developer.wordpress.org/reference/classes/wp_rest_autosaves_controller/create_post_autosave/)`wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php` |

Creates autosave for the specified post.

  | 
| [WP_REST_Meta_Fields::delete_meta_value()](https://developer.wordpress.org/reference/classes/wp_rest_meta_fields/delete_meta_value/)`wp-includes/rest-api/fields/class-wp-rest-meta-fields.php` |

Deletes a meta value for an object.

  | 
| [WP_REST_Meta_Fields::update_multi_meta_value()](https://developer.wordpress.org/reference/classes/wp_rest_meta_fields/update_multi_meta_value/)`wp-includes/rest-api/fields/class-wp-rest-meta-fields.php` |

Updates multiple meta values for an object.

  | 
| [WP_REST_Meta_Fields::update_meta_value()](https://developer.wordpress.org/reference/classes/wp_rest_meta_fields/update_meta_value/)`wp-includes/rest-api/fields/class-wp-rest-meta-fields.php` |

Updates a meta value for an object.

  | 
| [get_metadata()](https://developer.wordpress.org/reference/functions/get_metadata/)`wp-includes/meta.php` |

Retrieves the value of a metadata field for the specified object type and ID.

  | 
| [update_metadata()](https://developer.wordpress.org/reference/functions/update_metadata/)`wp-includes/meta.php` |

Updates metadata for the specified object. If no value already exists for the specified object ID and metadata key, the metadata will be added.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/get_metadata_raw/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_metadata_raw/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_metadata_raw/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_metadata_raw%2F)
before being able to contribute a note or feedback.