WPDev.one
Core Function
View Source on Trac ↗

update_post_meta()

update_post_meta( mixed $post_id, mixed $meta_key, mixed $meta_value, mixed $prev_value = '' )

Updates a post meta field based on the given post ID.

Parameters 4 required

Name / Type Description
$post_id
int

Post ID.

Required
$meta_key
string

Metadata key.

Required
$meta_value
mixed

Metadata value. Must be serializable if non-scalar.

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

Required

Return Value

((int)
(int | bool) Meta ID if the key didn't exist, 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.

Function Information

Since Version
1.5.0
Source File
wp-includes/post.php
Advertisement