WordPress获取评论用户的信息

廖为祥 wordpressWordPress获取评论用户的信息已关闭评论298阅读模式

WordPress获取评论用户的信息那么,我们能不能再输出一些评论者的信息呢?比如:某读者的最后评论时间,总的评论文章,最后评论内容,在本站总的评论数等,通过下面的代码您可以轻松实现:

//获取指定用户评论总数目
function get_author_comment_count($comment_author_email) {
global $wpdb;
$comment_count = count($wpdb->get_results( "SELECT comment_ID as author_count FROM $wpdb->comments WHERE comment_author_email = '$comment_author_email' "));
return $comment_count;
}
//获取指定用户最后评论内容
function author_last_comment_content($comment_author_emails) {
$args = array( 'author_email' =>$comment_author_emails, 'number' => '1');
$comments = get_comments($args);
foreach($comments as $comment) : return $comment->comment_content;
endforeach;
}
//获取指定用户最后时间
function author_last_comment_time($comment_author_emails) {
$args = array( 'author_email' =>$comment_author_emails, 'number' => '1');
$comments = get_comments($args);
foreach($comments as $comment) : return $comment->comment_date_gmt;
endforeach;
}

继续阅读
廖为祥
  • 本文由 发表于 2022年12月13日 10:24:31
  • 除特别声明外,本站原创内容版权遵循 CC BY-NC-ND/2.5/CN协议规定