Title: update_{$meta_type}_metadata
Published: April 25, 2014
Last modified: May 20, 2026

---

# apply_filters( “update_{$meta_type}_metadata”, null|bool $check, int $object_id, string $meta_key, mixed $meta_value, mixed $prev_value )

## In this article

 * [Description](https://developer.wordpress.org/reference/hooks/update_meta_type_metadata/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/hooks/update_meta_type_metadata/?output_format=md#parameters)
 * [More Information](https://developer.wordpress.org/reference/hooks/update_meta_type_metadata/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/hooks/update_meta_type_metadata/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/update_meta_type_metadata/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/update_meta_type_metadata/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/update_meta_type_metadata/?output_format=md#user-contributed-notes)

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

Short-circuits updating metadata of a specific type.

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

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 hook names include:

 * `update_blog_metadata`
 * `update_post_metadata`
 * `update_comment_metadata`
 * `update_term_metadata`
 * `update_user_metadata`

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

 `$check`null|bool

Whether to allow updating metadata for the given type.

`$object_id`int

ID of the object metadata is for.

`$meta_key`string

Metadata key.

`$meta_value`mixed

Metadata value. Must be serializable if non-scalar.

`$prev_value`mixed

Previous value to check before updating.
 If specified, only update existing metadata
entries with this value. Otherwise, update all entries.

## 󠀁[More Information](https://developer.wordpress.org/reference/hooks/update_meta_type_metadata/?output_format=md#more-information)󠁿

 * This filter is applied before a metadata gets updated; it allows short-circuiting
   the updating of metadata of a specific type by returning a non-null value.
 * The dynamic portion of the hook, `$meta_type`, refers to the meta object type.
   For example, if a ‘user’ metadata gets updated, the hook would be ‘`update_user_metadata`‘.
 * The filter must return a `null` value (the value of `$check`) if the data is 
   be saved to the database. If it returns anything else, the ‘`update_metadata`‘
   function (and therefore the ‘`update_{$meta_type}_metadata`‘ filter) will return
   what the filter callbacks return.

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

    ```php
    $check = apply_filters( "update_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $prev_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.0/src/wp-includes/meta.php#L250)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/meta.php#L250-L250)

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

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

  |

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

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

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/update_meta_type_metadata/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/hooks/update_meta_type_metadata/?output_format=md#comment-content-4774)
 2.    [Steven Lin](https://profiles.wordpress.org/stevenlinx/)  [  5 years ago  ](https://developer.wordpress.org/reference/hooks/update_meta_type_metadata/#comment-4774)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fupdate_meta_type_metadata%2F%23comment-4774)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fupdate_meta_type_metadata%2F%23comment-4774)
 4.  Example migrated from Codex:
 5.  The example below skips saving the metadata with the key ‘foo’ and an empty value.
     For other metadata, continue the normal execution.
 6.      ```php
         add_action( 'init', 'wpdocs_init' );
     
         function wpdocs_init() {
            add_filter( 'update_user_metadata', 'wpdocs_update_foo', 10, 4 );
         }
     
         function wpdocs_update_foo( $check, $object_id, $meta_key, $meta_value ) {
     
            if ( 'foo' == $meta_key && empty( $meta_value ) ) {
               return false; // this means: stop saving the value into the database
            }
     
            return $check; // this means: go on with the normal execution in meta.php
         }
         ```
     
 7.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fupdate_meta_type_metadata%2F%3Freplytocom%3D4774%23feedback-editor-4774)
 8.   [Skip to note 4 content](https://developer.wordpress.org/reference/hooks/update_meta_type_metadata/?output_format=md#comment-content-4947)
 9.    [crstauf](https://profiles.wordpress.org/crstauf/)  [  5 years ago  ](https://developer.wordpress.org/reference/hooks/update_meta_type_metadata/#comment-4947)
 10. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fupdate_meta_type_metadata%2F%23comment-4947)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fupdate_meta_type_metadata%2F%23comment-4947)
 11. Similar to stevenlinx’s example, to skip saving empty value of `foo` to user metadata.
     Note that this could create problems if the user is attempting to clear previously
     entered data; an additional hook should be included that deletes the `foo` key
     from the user’s metadata if the value is empty.
 12.     ```php
         add_filter( 'update_user_metadata', function( $check, $object_id, $meta_key, $meta_value ) {
     
             // Already short-circuited; bail.
             if ( null !== $check )
                 return $check;
     
             // Bail if not saving the 'foo' metadata.
             if ( 'foo' !== $meta_key )
                 return null;
     
             // If meta value is not empty, then we _want_ to save it.
             if ( ! empty( $meta_value ) )
                 return null;
     
             // Prevent saving empty value to user's 'foo' metadata.
             return false;
         }, 10, 4 );
         ```
     
 13.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fupdate_meta_type_metadata%2F%3Freplytocom%3D4947%23feedback-editor-4947)

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