I know how to count comment per post, user and in total but i am
having problems getting the total amount of comments post in a specific post type.
I guess i can loop trough all the posts and count each one
comments but i am looking for something faster and less
resource expensive
Appreciate your help
I got this so far (i think this is a bad way but i might be wrong):
/*** ALL COMMENTS COUNT BY POST TYPE ***/
function countCptCommentsTotal() {
// FAQ ARGS
$faqStatsArgs = array(
'post_type' => 'some_post_type',
'post_status' => 'publish',
'posts_per_page' => -1
);
$faqstats_query = new WP_Query($faqStatsArgs);
// THE LOOP
$allAnswers = 0;
while ($faqstats_query->have_posts()) {
$faqstats_query->the_post();
$curfaqid = get_the_ID();
$allAnswers = $allAnswers + countPostComments($curfaqid);
}
wp_reset_query();
return $allAnswers;
}
How about direct sql with a simple subquery to first get all the post ids of your custom post type ex:
Usage:
Simply do a plain MySQL Query that
sum
s thecomment_count
row. The following plugin as an example:You can then just call it to display the total amount of this post type.