根据作者和日期确定是否存在评论。
原型
comment_exists( string $comment_author, string $comment_date, string $timezone = 'blog' )
描述
为获得最佳性能,请使用$ timezone =’gmt’,它会查询正确编制索引的字段。由于遗留原因,$ timezone的默认值为“blog”。
参数
$comment_author
(string)
(Required)
评论的作者。
$comment_date
(string)
(Required)
评论日期。
$timezone
(string)
(Optional)
时区。接受’博客’或’gmt’。
返回值
(mixed)
评论发布ID成功。
源文件
路径:wp-admin/includes/comment.php
<?php
...
function comment_exists( $comment_author, $comment_date, $timezone = 'blog' ) {
global $wpdb;
$date_field = 'comment_date';
if ( 'gmt' === $timezone ) {
$date_field = 'comment_date_gmt';
}
return $wpdb->get_var( $wpdb->prepare("SELECT comment_post_ID FROM $wpdb->comments
WHERE comment_author = %s AND $date_field = %s",
stripslashes( $comment_author ),
stripslashes( $comment_date )
) );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/comment_exists/