[resolved] comment count gone??? (4 posts)

  1. cogmios
    Posted 5 years ago #

    A while ago I imported a set of posts from another url. Only now I see that although a post HAS comments , the comment counter actually say ... 0 ??

    Can I fix that easily?

    see e.g.:

    There is something somewhere in the back of my brain about this, maybe i should search first.. oh yes... its the comment_count field in wp_posts.

    hmmm what was it again hmmm was it a plugin was it a standard call to recount uhm..... (almost on tip of tongue)

  2. cogmios
    Posted 5 years ago #

    ok this is handy: http://www.ankurb.info/2008/11/16/reseting-post-and-comment-count-in-wordpress/

    unfortunatly i am on multisite but that is easy to fix.

  3. cogmios
    Posted 5 years ago #

    ok worked with

    include('wp-config.php'); // Needed for login details to WordPress database to make necessary changes
    function updateCount()
            $posts = mysql_fetch_row(mysql_query("SELECT ID FROM wp_8_posts ORDER BY ID DESC LIMIT 1")); // Fetch row in WordPress database containing information about post data
            for ($i = 1; $i < ($posts[0] + 1); $i++)
         $comments = mysql_query("SELECT SQL_CALC_FOUND_ROWS comment_ID FROM wp_8_comments WHERE comment_post_ID = '$i' AND comment_approved = 1;") or die("Failed to calculate number of approved comments"); // Calculate the number of approved comments for a post and store in a variable. If unsuccessful, end program.
         mysql_query("UPDATE wp_8_posts SET comment_count = '".mysql_num_rows($comments)."' WHERE id = '$i';") or die("Failed to update the number of comments calculated"); // Update the comment count using the comment number fetched earlier. If unsuccessful, end program
         echo "Updated Post #$i - ".mysql_num_rows($comments)." comments <br />"; // Display message to user for each post comment count successfully updated

    the output message could be a bit better with also displaying the new amount of comments but what the heck :)

  4. esmi
    Forum Moderator
    Posted 5 years ago #

    Thanks for posting the solution.

Topic Closed

This topic has been closed to new replies.

About this Topic