• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress core a2z

WordPress core a2z

WordPress core only

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / 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

Published: 25th November 2019 | Last updated: 25th November 2019

Primary Sidebar

Information

Function name: add_post_meta
Plugin ref: WordPress
Version: 5.6
Sourcefile: wp-includes/post.php
File ref: wp-includes/post.php
Deprecated?: No
API Letters: A,M,P

Footer

WP-a2z
WordPress core a2z
WordPress core only
WordPress 5.6
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  core.wp-a2z.org
© Copyright WP-a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites