update_metadata ( $meta_type, $object_id, $meta_key, $meta_value, $prev_value = '' )

  • (string) meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', or any other object type with an associated meta table.
  • (int) object_id ID of the object metadata is for.
  • (string) meta_key Metadata key.
  • (mixed) meta_value Metadata value. Must be serializable if non-scalar.
  • (mixed) prev_value Optional. Previous value to check before updating. If specified, only update existing metadata entries with this value. Otherwise, update all entries. Default empty string.
  • (int|bool) The new meta field ID if a field with the given key didn't exist and was therefore added, true on successful update, false on failure or if the value passed to the function is the same as the one that is already in the database.
Defined at:


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

Related Functions

update_meta, update_metadata_by_mid, delete_metadata, update_meta_cache, add_metadata

Top Google Results

User discussions

wpseek mobile