add_post_meta() – Adds a meta field to the given post.

You appear to be a bot. Output may be restricted

Description

Adds a meta field to the given post.

Post meta data is called "Custom Fields" on the Administration Screen.

Usage

$int|false = add_post_meta( $post_id, $meta_key, $meta_value, $unique );

Parameters

$post_id
( int ) required – Post ID.
$meta_key
( string ) required – Metadata name.
$meta_value
( mixed ) required – Metadata value. Must be serializable if non-scalar.
$unique
( bool ) optional – Optional. Whether the same key should not be added. Default false.

Returns

int|false Meta ID on success, false on failure.

Source

File name: wordpress/wp-includes/post.php
Lines:

1 to 9 of 9
function add_post_meta( $post_id, $meta_key, $meta_value, $unique = false ) {
  // Make sure meta is added to the post, not a revision.
  $the_post = wp_is_post_revision( $post_id );
  if ( $the_post ) {
    $post_id = $the_post;
  }

  return add_metadata( 'post', $post_id, $meta_key, $meta_value, $unique );
}
 

 View on GitHub View on Trac