Post Pic

How to: Display the total number of trackbacks

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

Dec 13 2008 12:47

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.

Dec 13 2008 12:55

@Austin: Thank you! I have modified the code.

Jan 31 2009 18:15

How can I display the number of trackbacks for a specific post.

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required