复制代码代码如下://获取文章评论数,不包含作者自己function get_comments_number_filter_author() { global $wpdb, $post; //需要过滤作者的
复制代码代码如下:
//获取文章评论数,不包含作者自己
function get_comments_number_filter_author() {
global $wpdb, $post;
//需要过滤作者的名称
$author = '作者名称';
$comments = $wpdb->get_results("SELECT count(0) as total FROM $wpdb->comments WHERE comment_post_ID = $post->ID AND comment_type = '' AND comment_approved = '1' AND comment_author != '$author'");
return $comments[0]->total;
}
代码原理比较简单,就是自己编写sql语句从comments表示获取评论总数,其中不包括文章作者的评论。
将该方法复制到主题的funtions.PHP文件,在需要的地方调用就行了。
--结束END--
本文标题: wordpress获取文章评论数过滤掉作者代码分享
本文链接: https://www.lsjlt.com/news/32120.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-02-29
2024-02-29
2024-02-27
2023-10-27
2023-10-26
2023-10-25
2023-10-21
2023-10-21
2023-10-18
2023-10-12
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0