WordPress.org

Forums

[resolved] Resetting Pingback Counter? (2 posts)

  1. ICanHazCode
    Member
    Posted 2 years ago #

    I was having some trouble with my comment count not displaying correctly after using the Hide Trackbacks plugin. After disabling the plugin, I found this code to add to functions.php:

    <?php
    add_filter('get_comments_number', 'comment_count', 0);
    function comment_count( $count ) {
    if ( ! is_admin() ) {
    global $id;
    $comments_by_type = &separate_comments(get_comments('status=approve&post_id=' . $id));
    return count($comments_by_type['comment']);
    } else {
    return $count;
    }
    }
    ?>

    Now my comments show correctly except my ping count is not reflected in the comment count. Removing this function does not fix the ping count.

    The problem here is that I am using a code in my loop.php to display the comment count for a post IF the post has comments. So what happens is some posts have no comments but do have pings, so the comment bubble appears but it reads zero, no matter how many pings.

    Does anyone know how to either reset the ping counter function back to default to fix this, or a code I can put in the loop that will display comment count ONLY IF the post has comments (and not just pingbacks)?

    Any help is greatly appreciated.

  2. ICanHazCode
    Member
    Posted 2 years ago #

    Resetting the ping and comment count was resolved by placing the following code in functions.php:

    add_filter('get_comments_number', 'comment_count', 0);
    function comment_count( $count ) { //Ugly Patch
    	if ( ! is_admin() ) {
    		global $id;
    
    	$comments_by_type = &separate_comments(get_comments('status=approve&post_id=' . $id));
    		$comments_by_count = count($comments_by_type['comment']);
    		$pings_by_count = count($comments_by_type['pings']);
    		$sum_total = $comments_by_count + $pings_by_count;
    		return $sum_total;
    	} else {
    		return $count;
    	}
    }

Topic Closed

This topic has been closed to new replies.

About this Topic