函数文档

delete_comment_meta()

💡 云策文档标注

概述

delete_comment_meta() 函数用于从评论中删除匹配条件的元数据。它基于键或键值对进行匹配,并支持删除所有匹配键的元数据。

关键要点

  • 函数基于 $comment_id、$meta_key 和可选的 $meta_value 参数删除评论元数据。
  • 如果提供 $meta_value,则仅删除键值对完全匹配的行,避免删除重复键的元数据。
  • 出于历史原因,输入时元键和元值需要“转义斜杠”。
  • 返回布尔值:成功为 true,失败为 false。

代码示例

// 删除评论 ID 5 中键为 'my_meta_key' 的所有元数据
delete_comment_meta( 5, 'my_meta_key' );

// 删除评论 ID 5 中键为 'my_meta_key' 且值为 'foo' 的元数据
delete_comment_meta( 5, 'my_meta_key', 'foo' );

📄 原文内容

Removes metadata matching criteria from a comment.

Description

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.

For historical reasons both the meta key and the meta value are expected to be “slashed” (slashes escaped) on input.

Parameters

$comment_idintrequired
Comment ID.
$meta_keystringrequired
Metadata name.
$meta_valuemixedoptional
Metadata value. If provided, rows will only be removed that match the value.
Must be serializable if non-scalar. Default empty string.

Return

bool True on success, false on failure.

Source

function delete_comment_meta( $comment_id, $meta_key, $meta_value = '' ) {
	return delete_metadata( 'comment', $comment_id, $meta_key, $meta_value );
}

Changelog

Version Description
2.9.0 Introduced.

User Contributed Notes