So I imported a bunch of posts from another blog. It all worked well except for the comment count. It tells me there are zero comments for each post (but when you open the post, there are comments there). I tried the below code to fix it. It sort of worked, but unfortunately, it didn’t correct the comment count in all places — only in some. Is there some other code I can use to correct the comment count? Thanks!
<?php
include(‘wp-config.php’);
$posts = mysql_fetch_row(mysql_query(“SELECT ID FROM wp_posts ORDER BY ID DESC LIMIT 1”));
function update_comment_count(){
for($i=1;$i<($posts[0]+1);$i++){
$comments = mysql_query(“SELECT SQL_CALC_FOUND_ROWS comment_ID FROM wp_comments WHERE comment_post_ID = ‘$i’ AND comment_approved = 1;”);
mysql_query(“UPDATE wp_posts SET comment_count = ‘”.mysql_num_rows($comments).”‘ WHERE id = ‘$i’;”);
}
return true;
}