add_post_meta()
热度:99Function:在给定帖子中添加元字段。
版本
20190729
所属分类
Functions
可使用页面
All
默认值
无
add_post_meta( int $post_id, string $meta_key, mixed $meta_value, bool $unique = false )
在给定帖子中添加元字段。
描述:
发布元数据在管理屏幕上称为“自定义字段”。
参数:
$post_id
(int) (Required) 帖子ID。
$meta_key
(string) (Required) 元数据名称。
$meta_value
(mixed) (Required) 元数据值。如果是非标量,则必须可序列化。
$unique
(bool) (Optional) 是否不应添加相同的密钥。
Default value: false
Return(返回):
(int|false) 成功时的元ID,失败时为假。
示例:
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 );
}