添加$ _POST superglobal中定义的post元数据,以获取具有给定ID的帖子。

原型

add_meta( int $post_ID )

参数

$post_ID (int) (Required)

返回值

(int|bool)  

源文件

路径:wp-admin/includes/post.php

<?php
...
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
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/add_meta/