Days
:
Hours
:
Minutes
:
Seconds

Tuning - Car Detailing & Dealer 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. Replace DB_HOSTDB_USER, and DB_PASSWORD with your WordPress database credentials. These can be found in your wp-config.php file or your hosting control panel.
  2. Save this file as comments-fix.php on your computer.
  3. Upload the file to your WordPress site’s root directory using an FTP client or your hosting file manager.
  4. In your web browser, visit the file you uploaded: https://yourwebsite.com/comments-fix.php. Replace yourwebsite.com with your actual domain.
  5. The script will run and update the counts for your categories, tags, and comments.

Step 3: Remove the Script

Once the script has been executed, delete the comments-fix.php file from your server to prevent any security risks.

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.

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