Ping/Track/Comment Count


This plugin, co-created by Chris J. Davis, Scott Merrill, and Mark Jaquith in one magical rainbow-filled night contains two functions that return and echo the number of pingbacks, trackbacks, combined pings or regular comments for a WordPress entry.

This is of particular use to people who want to separate their regular comments from their pings. The plugin is “smart” and will grab all the numbers in one go the first time you call it, so that subsequent calls use no database queries, making it very efficient.



There are two functions you can use: get_comment_type_count() (which returns the value) and comment_type_count() (which echoes the value).

Both functions operate identically, and take 2 optional parameters. The first parameter is the type of comment you would like returned (defaults to ‘all’). Your options are trackback, pingback, ping, and comment.

For example, pretend that a post has 1 pingback, 2 trackbacks, and 4 regular comments.

comment_type_count('pingback'); // prints "1"
comment_type_count('trackback'); // prints "2"
comment_type_count('ping'); // prints "3" (1 pingback + 2 trackbacks)
comment_type_count('comment'); // prints "4"
comment_type_count(); // prints "7" (1 pingback + 2 trackbacks + 4 comments)

The second parameter, which is also optional, is a post ID. By default, the function just gives you the number for the current post being processed in “the loop.” By passing a specific post ID, you can get the count for any post ID you wish.

comment_type_count('pingback', 534); // prints number of pingbacks on entry 534


I've spent a lot of time writing this code and supporting it. If you derive some benefit from this code, please consider showing your gratitute in a more tangible way. Thanks!

Donate with Wishlist