Action hook 'update_postmeta'

in WP Core File wp-includes/meta.php at line 957

View Source

update_postmeta

Action Hook
Description
Short-circuits updating metadata of a specific type by meta ID. The dynamic portion of the hook name, `$meta_type`, refers to the meta object type (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_post_metadata_by_mid` - `update_comment_metadata_by_mid` - `update_term_metadata_by_mid` - `update_user_metadata_by_mid`

Hook Information

File Location wp-includes/meta.php View on GitHub
Hook Type Action
Line Number 957

Hook Parameters

Type Name Description
null|bool $check Whether to allow updating metadata for the given type.
int $meta_id Meta ID.
mixed $meta_value Meta value. Must be serializable if non-scalar.
string|false $meta_key Meta key, if provided. $check = apply_filters( "update_{$meta_type}_metadata_by_mid", null, $meta_id, $meta_value, $meta_key ); if ( null !== $check ) { return (bool) $check; } // Fetch the meta and go on if it's found. $meta = get_metadata_by_mid( $meta_type, $meta_id ); if ( $meta ) { $original_key = $meta->meta_key; $object_id = $meta->{$column}; /* If a new meta_key (last parameter) was specified, change the meta key, otherwise use the original key in the update statement.

Usage Examples

Basic Usage
<?php
// Hook into update_postmeta
add_action('update_postmeta', 'my_custom_function', 10, 4);

function my_custom_function($check, $meta_id, $meta_value, $meta_key) {
    // Your custom code here
}

Source Code Context

wp-includes/meta.php:957 - How this hook is used in WordPress core
<?php
 952  		/** This action is documented in wp-includes/meta.php */
 953  		do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );
 954  
 955  		if ( 'post' === $meta_type ) {
 956  			/** This action is documented in wp-includes/meta.php */
 957  			do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value );
 958  		}
 959  
 960  		// Run the update query, all fields in $data are %s, $where is a %d.
 961  		$result = $wpdb->update( $table, $data, $where, '%s', '%d' );
 962  		if ( ! $result ) {

PHP Documentation

<?php
/**
	 * Short-circuits updating metadata of a specific type by meta ID.
	 *
	 * The dynamic portion of the hook name, `$meta_type`, refers to the meta object type
	 * (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_post_metadata_by_mid`
	 *  - `update_comment_metadata_by_mid`
	 *  - `update_term_metadata_by_mid`
	 *  - `update_user_metadata_by_mid`
	 *
	 * @since 5.0.0
	 *
	 * @param null|bool    $check      Whether to allow updating metadata for the given type.
	 * @param int          $meta_id    Meta ID.
	 * @param mixed        $meta_value Meta value. Must be serializable if non-scalar.
	 * @param string|false $meta_key   Meta key, if provided.
	 */
	$check = apply_filters( "update_{$meta_type}_metadata_by_mid", null, $meta_id, $meta_value, $meta_key );
	if ( null !== $check ) {
		return (bool) $check;
	}

	// Fetch the meta and go on if it's found.
	$meta = get_metadata_by_mid( $meta_type, $meta_id );
	if ( $meta ) {
		$original_key = $meta->meta_key;
		$object_id    = $meta->{$column};

		/*
		 * If a new meta_key (last parameter) was specified, change the meta key,
		 * otherwise use the original key in the update statement.
		 */
Quick Info
  • Hook Type: Action
  • Parameters: 4
  • File: wp-includes/meta.php
Related Hooks

Related hooks will be displayed here in future updates.