Days
:
Hours
:
Minutes
:
Seconds

Paragon - Business WordPress Theme $69 $19

View Now
Skip to content Skip to sidebar Skip to footer

Fixing Category and Comment Count Issues After WordPress Import

Find out how to fix category and comment count issues in WordPress while easily adjusting the size and position of your Layer content.

After importing your WordPress site, you may notice discrepancies in category and comment counts. This can be frustrating, but fortunately, there are straightforward fixes to resolve these inaccuracies.

Why Category and Comment Counts May Be Incorrect

When you use the built-in WordPress importer, it sometimes fails to accurately reflect comment and category counts on your site. Although the data is imported correctly and visible in the admin area, the displayed counts on the front end might need to be corrected.

Steps to Fix Category and Comment Counts

Before making any changes, it’s crucial to back up your WordPress site. We recommend using a reliable backup plugin like Duplicator.

Step 1: Back Up Your WordPress Site

Create a full WordPress site backup using Duplicator or another backup plugin. This ensures that you can restore your site if something goes wrong.

Step 2: Update Category and Comment Counts

To fix the issue, you must run a simple script that recalculates and updates the counts. Here’s how:

Open a plain text editor like Notepad and paste the following PHP code:

<?php

include(“wp-config.php”);

$myConnection = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);

if (!mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD)) { die(‘Could not connect: ‘ . mysqli_error()); }

if (!mysqli_select_db($myConnection, DB_NAME)) { die(‘Could not connect: ‘ . mysqli_error()); }

$result = mysqli_query($myConnection, “SELECT term_taxonomy_id FROM “.$table_prefix.”term_taxonomy”);

while ($row = mysqli_fetch_array($result)) {

  $term_taxonomy_id = $row[‘term_taxonomy_id’];

  $countresult = mysqli_query($myConnection, “SELECT count(*) FROM “.$table_prefix.”term_relationships WHERE term_taxonomy_id = ‘$term_taxonomy_id'”);

  $countarray = mysqli_fetch_array($countresult);

  $count = $countarray[0];

  mysqli_query($myConnection, “UPDATE “.$table_prefix.”term_taxonomy SET count = ‘$count’ WHERE term_taxonomy_id = ‘$term_taxonomy_id'”);

}

$result = mysqli_query($myConnection, “SELECT ID FROM “.$table_prefix.”posts”);

while ($row = mysqli_fetch_array($result)) {

  $post_id = $row[‘ID’];

  $countresult = mysqli_query($myConnection, “SELECT count(*) FROM “.$table_prefix.”comments WHERE comment_post_ID = ‘$post_id’ AND comment_approved = 1”);

  $countarray = mysqli_fetch_array($countresult);

  $count = $countarray[0];

  mysqli_query($myConnection, “UPDATE “.$table_prefix.”posts SET comment_count = ‘$count’ WHERE ID = ‘$post_id'”);

}

?>

  1. Please replace DB_HOST, DB_USER, and DB_PASSWORD with your actual WordPress database host (typically localhost), database username, and password.

    You can find this information by logging into your WordPress hosting control panel or checking the wp-config.php file using a file manager.

    After updating the details, save the file as comments-fix.php on your desktop.

    Next, upload this file to your site’s root directory using an FTP client or the file manager in your hosting control panel.

    Once the upload is complete, open your web browser and navigate to:
    https://example.com/comments-fix.php
    Remember to replace example.com with your site’s actual URL.

    Visiting this file will execute the script, which will loop through your posts, categories, tags, and comments to refresh the count.

wp-comment-count-fixed

Once you have updated your WordPress comment count, delete the comments-fix.php file from your server.

Bonus Tip: Adjust Comment Settings

After importing your WordPress site, consider reconfiguring your comment settings.

Decide if you want to allow comments on new posts by default or manage them individually for each post.

Moderation settings enable you to maintain comment quality. You can approve comments or automatically allow those from trusted users manually.

thrive-comments-moderation-min

Email notifications keep you informed about new comments, alerting you when someone comments or a comment requires approval. If you enable moderation, you can notify users when their comments are approved.

To adjust your comment settings, navigate to Settings » Discussion in your WordPress dashboard. For enhanced functionality, consider using Thrive Comments.

Thrive Comments is a powerful WordPress plugin that covers basic configurations and enhances reader engagement with features like upvotes, downvotes, likes, badges, and social media sharing.

Additional Comment Settings

After fixing the counts, you may want to adjust your comment settings:

  • Decide whether to allow comments on new posts by default.
  • Enable or disable comments for individual posts.
  • Configure moderation settings to control the quality of comments.
  • Set up email notifications for new comments and moderation.

For enhanced comment management, consider using the Thrive Comments plugin, which offers features like upvotes, downvotes, likes, badges, and social media sharing.

With these steps, your WordPress site should accurately display category and comment counts, providing a better user experience.

Preview the responsive settings while editing the options to ensure accuracy.

For the Updates

Exploring ideas at the intersection of design, code, and technology. Subscribe to our newsletter and always be aware of all the latest updates.

Leave a comment

Download a Free Theme