最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

WordPress comment count to include attachment comments

programmeradmin4浏览0评论

How can I make the comment count on a post on my index page include comments that have been made on, in my case, individual gallery pictures that are included in the post? It seems that comments made on attachments like this aren't counted using the standard WordPress comments functions.

How can I make the comment count on a post on my index page include comments that have been made on, in my case, individual gallery pictures that are included in the post? It seems that comments made on attachments like this aren't counted using the standard WordPress comments functions.

Share Improve this question asked Jul 9, 2012 at 9:59 JosJos 412 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

A gallery is a post with attached media. So maybe you'll find hints like this : just hook on get_comment_numbers() and pass $attachment_id.

I think in this case you'll have to add an SQL query to get the comment count for attachment and then you'll be able to add it to the total number of comments for post , something like this :

global $wpdb;
$wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE post_type = 'attachment'" ) ;

I haven't tested yet. Hopefully this will help you.

发布评论

评论列表(0)

  1. 暂无评论