delete_post_meta()

delete_post_meta()函数是Wordpress函数,删除给定post ID的post元字段。

delete_post_meta( int $post_id, string $meta_key, mixed $meta_value = ” )

说明(Description)

可以基于键或键和值进行匹配。基于键和值进行删除将避免删除具有相同键的重复元数据。如果需要,它还允许删除与密钥匹配的所有元数据。


参数(Parameters)

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

返回(Return)

(bool)成功时正确,失败时错误。


源码(Source)

/**
 * Remove metadata matching criteria from a post.
 *
 * You can match based on the key, or key and value. Removing based on key and
 * value, will keep from removing duplicate metadata with the same key. It also
 * allows removing all metadata matching key, if needed.
 *
 * @since 1.5.0
 *
 * @param int    $post_id    Post ID.
 * @param string $meta_key   Metadata name.
 * @param mixed  $meta_value Optional. Metadata value. Must be serializable if
 *                           non-scalar. Default empty.
 * @return bool True on success, false on failure.
 */
function delete_post_meta( $post_id, $meta_key, $meta_value = '' ) {
	// Make sure meta is added to the post, not a revision.
	if ( $the_post = wp_is_post_revision($post_id) )
		$post_id = $the_post;
	return delete_metadata('post', $post_id, $meta_key, $meta_value);
}
更新版本源码位置使用被使用
1.5.0wp-includes/post.php:2097222

笔记(Notes)

默认用法
其他例子
使用此函数删除特定的键值对时要非常小心。如delete_metadata()文档中所述,为$meta_value提供空字符串将导致完全跳过检查,从而删除所有键!

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索