I wish to display the number of trackbacks
, pingbacks
and comments
a post has. I've read all about them and I am wondering if there is a simple solution, that I am not seeing, available.
I know that wp_count_comments
(trac line 1188) searches in WPs cache before making a database query and I want to know if there is such a thing for pingbacks and trackbacks.
Right now I am using this modified code to show the number of comments, trackbacks, pingbacks and pings(trackbacks + pingbacks)
function commentCount( $type = 'pings' ) {
global $wpdb;
if ( $type == 'pings' ) {
$typeSql = 'comment_type != ""';
} elseif ( $type == 'trackbacks' ) {
$typeSql = 'comment_type = "trackback"';
} elseif ( $type == 'pingbacks' ) {
$typeSql = 'comment_type = "pingback"';
}
$result = $wpdb->get_var( '
SELECT
COUNT(comment_ID)
FROM
' . $wpdb->comments . '
WHERE
' . $typeSql . ' AND
comment_approved="1" AND
comment_post_ID= ' . get_the_ID()
);
return $result;
}
$comments = wp_count_comments( get_the_ID() );
$trackbacks = commentCount( 'trackbacks' );
$pingbacks = commentCount( 'trackbacks' );
$pings = commentCount( 'pings' );