Family Encyclopedia >> Electronics

How to Fix Incorrect Comment Counts and Category Numbers After WordPress Import

Have you noticed incorrect comment counts after importing your WordPress site? The built-in importer successfully transfers comments, which are visible in your dashboard, but fails to update the displayed counts on posts. This common issue also affects category, tag, and custom taxonomy counts. In this guide, we'll walk you through a reliable fix based on years of hands-on WordPress experience.

How to Fix Incorrect Comment Counts and Category Numbers After WordPress Import

As shown above, counts incorrectly show as 0. Follow these proven steps to correct them.

Video Walkthrough

Subscribe to WPBeginner for step-by-step video tutorials. Prefer reading? Continue below.

Always start with a full site backup before major changes. We recommend BackupBuddy, the most comprehensive WordPress backup plugin available.

Next, open a plain text editor like Notepad++ and paste this secure, tested PHP script:

<?php
require_once( dirname( __FILE__ ) . '/wp-load.php' );
global $wpdb;

// Update post comment counts
$wpdb->query( "UPDATE {$wpdb->posts} SET comment_count = ( SELECT COUNT(*) FROM {$wpdb->comments} WHERE {$wpdb->comments}.comment_post_ID = {$wpdb->posts}.ID AND {$wpdb->comments}.comment_approved = '1' )" );

// Update taxonomy counts (categories, tags, custom taxonomies)
$wpdb->query( "UPDATE {$wpdb->term_taxonomy} tt SET `count` = ( SELECT COUNT(*) FROM {$wpdb->term_relationships} tr WHERE tr.term_taxonomy_id = tt.term_taxonomy_id )" );

echo 'Counts updated successfully! Delete this file now for security.';
?>

Replace any database details if needed (though wp-load.php handles this automatically). Save as comments-fix.php on your desktop.

Upload to your site's root directory using FTP or your hosting file manager.

Access it in your browser: https://example.com/comments-fix.php (replace example.com with your domain).

The script loops through posts and taxonomies, accurately recounting and updating everything.

How to Fix Incorrect Comment Counts and Category Numbers After WordPress Import

Critical: Delete comments-fix.php from your server immediately after running to prevent security risks.

Your site should now display correct counts. For more, see our guide on common WordPress errors.

Liked this? Subscribe to our WordPress YouTube channel, follow us on Twitter and Google+.