add_meta( int $post_id ): int|bool
- Since
- 1.2.0
- Source
wp-admin/includes/post.php:999
Adds post meta data defined in the
$_POST superglobal for a post with given ID.Parameters
$post_idint
Return
int|bool
Uses · 5
- wp_unslash()Removes slashes from a string or recursively removes slashes from strings within an array.
- is_protected_meta()Determines whether a meta key is considered protected.
- current_user_can()Returns whether the current user has the specified capability.
- wp_slash()Adds slashes to a string or recursively adds slashes to strings within an array.
- add_post_meta()Adds a meta field to the given post.
Used by · 3
- edit_post()Updates an existing post with values provided in `$_POST`.
- wp_ajax_add_meta()Handles adding meta via AJAX.
- wp_write_post()Creates a new post from the "Write Post" form using `$_POST` information.
Source
function add_meta( $post_id ) { $post_id = (int) $post_id; $metakeyselect = isset( $_POST['metakeyselect'] ) ? wp_unslash( trim( $_POST['metakeyselect'] ) ) : ''; $metakeyinput = isset( $_POST['metakeyinput'] ) ? wp_unslash( trim( $_POST['metakeyinput'] ) ) : ''; $metavalue = isset( $_POST['metavalue'] ) ? $_POST['metavalue'] : ''; if ( is_string( $metavalue ) ) { $metavalue = trim( $metavalue ); } if ( ( ( '#NONE#' !== $metakeyselect ) && ! empty( $metakeyselect ) ) || ! empty( $metakeyinput ) ) { /* * We have a key/value pair. If both the select and the input * for the key have data, the input takes precedence. */ if ( '#NONE#' !== $metakeyselect ) { $metakey = $metakeyselect; } if ( $metakeyinput ) { $metakey = $metakeyinput; // Default. } if ( is_protected_meta( $metakey, 'post' ) || ! current_user_can( 'add_post_meta', $post_id, $metakey ) ) { return false; } $metakey = wp_slash( $metakey ); return add_post_meta( $post_id, $metakey, $metavalue ); } return false;}History
Introduced in 1.2.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-admin/includes/post.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.