
Some time ago, I shown you how to display the total number of comments on your WordPress blog. With a little modification, this recipe can be used to display the total number of trackbacks. This is what I’m going to show you today.

Some time ago, I shown you how to display the total number of comments on your WordPress blog. With a little modification, this recipe can be used to display the total number of trackbacks. This is what I’m going to show you today.
To achieve this recipe, we first have to create a function. paste the following code on the functions.php file from your theme:
function tb_count() {
global $wpdb;
$count = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_type = 'pingback' OR comment_type = 'trackback'";
echo $wpdb->get_var($count);
}
Once the file is saved, you can call the function anywhere you want:
<?php tb_count(); ?>
8 Responses
You need to change the where clause to
WHERE comment_type = 'pingback' OR comment_type = 'trackback'Currently your query returns only the pingback count, but I think you probably want to include both trackbacks and pingbacks.
@Austin: Thank you! I have modified the code.
How can I display the number of trackbacks for a specific post.
Trackbacks: