Title: get_metadata_default
Published: August 11, 2020
Last modified: August 20, 2026

---

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

## In this article

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

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

Retrieves default metadata value for the specified meta key and object.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/get_metadata_default/?output_format=md#description)󠁿

By default, an empty string is returned if `$single` is true, or an empty array 
if it’s false.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_metadata_default/?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`stringrequired

Metadata key.

`$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_default/?output_format=md#return)󠁿

 mixed An array of default values if `$single` is false.
 The default value of the
meta field if `$single` is true.

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

    ```php
    function get_metadata_default( $meta_type, $object_id, $meta_key, $single = false ) {
    	if ( $single ) {
    		$value = '';
    	} else {
    		$value = array();
    	}

    	/**
    	 * Filters the default metadata value for a specified meta key and object.
    	 *
    	 * 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).
    	 *
    	 * Possible filter names include:
    	 *
    	 *  - `default_blog_metadata`
    	 *  - `default_post_metadata`
    	 *  - `default_comment_metadata`
    	 *  - `default_term_metadata`
    	 *  - `default_user_metadata`
    	 *
    	 * @since 5.5.0
    	 *
    	 * @param mixed  $value     The value to return, either a single metadata value or an array
    	 *                          of values depending on the value of `$single`.
    	 * @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.
    	 */
    	$value = apply_filters( "default_{$meta_type}_metadata", $value, $object_id, $meta_key, $single, $meta_type );

    	if ( ! $single && ! wp_is_numeric_array( $value ) ) {
    		$value = array( $value );
    	}

    	return $value;
    }
    ```

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

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

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

Filters the default metadata value for a specified meta key and object.

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

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

Determines if the variable is a numeric-indexed array.

  | 
| [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.

  |

| Used by | Description | 
| [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.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_metadata_default/?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_default%2F)
before being able to contribute a note or feedback.