Display Pingback And Trackback Counts In WordPress Admin

A trackback or a pingback is simply a type of notification that lets you know if and when someone has created a link to your site on their page. And it’s a good sign that your site will be taking in more traffic because of the added exposure.

Here’s a nice little trick that you might like to try out on your on your WordPress blog. It’s a hack that tallies the total number of trackbacks and pingbacks of each of your posts and then displays it in your admin page by adding an additional column labeled as ‘Counts’ at the end of the posts list.

As usual, applying this trick is simply done by adding a code to the functions.php file inside your theme folder.

Here’s the following code:

function commentCount($type = 'comments'){
if($type == 'trackbacks'):
$typeSql = 'comment_type = "trackback"';
$oneText = 'One :trackback';
$moreText = '% :trackbacks';
$noneText = 'No :trackbacks';
elseif($type == 'pingbacks'):
$typeSql = 'comment_type = "pingback"';
$oneText = 'One :pingback';
$moreText = '% :pingbacks';
$noneText = 'No :pingbacks';
endif;
global $wpdb;
$result = $wpdb->get_var('
SELECT
COUNT(comment_ID)
FROM
'.$wpdb->comments.'
WHERE
'.$typeSql.' AND
comment_approved="1" AND
comment_post_ID= '.get_the_ID()
);
if($result == 0):
echo str_replace('%', $result, $noneText);
elseif($result == 1):
echo str_replace('%', $result, $oneText);
elseif($result > 1):
echo str_replace('%', $result, $moreText);
endif;
}
add_filter('manage_posts_columns', 'posts_columns_counts', 1);
add_action('manage_posts_custom_column', 'posts_custom_columns_counts', 1, 2);
function posts_columns_counts($defaults){
$defaults['wps_post_counts'] = __('Counts');
return $defaults;
}
function posts_custom_columns_counts($column_name, $id){
if($column_name === 'wps_post_counts'){
commentCount('trackbacks'); echo "<br />";
commentCount('pingbacks');
}
 }

Credit for the code goes to InstantShift! I hope you all find this useful.

Incoming search terms for the article:

Related Posts

Creating a Psychedelic Art Effect in Your Portraits

EWWW Image Optimizer

Inspirational Photo Retouches By Cristian Girotto

Create Your Own Sticker Design Via Photoshop