add_meta( int $post_ID )
Add post meta data defined in $_POST superglobal for post with given ID.
Description Description
Parameters Parameters
- $post_ID
-
(int) (Required)
Return Return
(int|bool)
Source Source
File: wp-admin/includes/post.php
883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 | 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; } // add_meta |
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
1.2.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Example
/*
* Unless you developed a custom post form that uses the custom field widget,
* there is little reason to use this function
*/
add_meta(
$post_ID
);