Support » Fixing WordPress » comment count gone???

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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.

    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
            }
        }
    
    updateCount();

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

    esmi

    (@esmi)

    Forum Moderator

    Thanks for posting the solution.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘comment count gone???’ is closed to new replies.