1. 首页
  2. WordPress 函数手册

add_post_meta()

add_post_meta( int $post_id, string $meta_key, mixed $meta_value, bool $unique = false )

将元字段添加到给定的post。
Adds a meta field to the given post.

目录锚点:#说明#参数#返回#源码#笔记


说明(Description)

Post元数据在管理屏幕上称为“自定义字段”。


参数(Parameters)

参数 类型 必填 说明
$post_id (int) 必需 邮政编码。
$meta_key (string) 必需 元数据名称。
$meta_value (mixed) 必需 元数据值。如果不是标量,则必须是可序列化的。
$unique (bool) 可选 是否不应添加相同的密钥。

返回(Return)

(int|false)Meta ID表示成功,false表示失败。


源码(Source)


更新版本 源码位置 使用 被使用
1.5.0 wp-includes/post.php:2072 17 2

笔记(Notes)

隐藏自定义字段
添加或更新唯一的自定义字段
默认用法

add_post_meta() 为WP2原创文章,链接:https://www.wp2.cn/functions/add_post_meta/