Family Encyclopedia >> Electronics

How to fix category and number of comments after WordPress import

Are you noticing incorrect comment count after WordPress import? Importing a WordPress site using the built-in importer can sometimes mess up the number of WordPress comments. While all comments are securely imported and visible in the admin area, your posts will show an incorrect comment count on your website. This same import error can also affect the category count and custom taxonomy count. In this article, we will show you how to fix category and comment count after importing WordPress.

How to fix category and number of comments after WordPress import

As you noticed in the screenshot above, after the import, our comment and category count shows 0 instead of the actual number. Let's take a look at how to fix it.

Video Walkthrough

Subscribe to WPBeginner

If you don't like the video or need more instructions, continue reading.

First you need to create a full WordPress backup of your site. You should do this every time you are going to make a major change to your site. We recommend using BackupBuddy, it is the most complete WordPress backup plugin on the market.

Once you have made the backup, we will move on to the next step.

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

 "; mysql_query (" UPDATE ". $ table_prefix." term_taxonomy SET count = '$ count' DONDE term_taxonomy_id = '$ term_taxonomy_id' "); $ resultado = mysql_query (" SELECCIONAR ID DE ". $ table_prefix. while ($ row = mysql_fetch_array ($ result)) $ post_id = $ row ['ID']; echo "post_id:". $ post_id. " count = "; $ countresult = mysql_query (" SELECT count (*) FROM ". $ table_prefix." comments WHERE comment_post_ID = '$ post_id' AND comment_approved = 1 "); $ countarray = mysql_fetch_array ($ countresult); $ count = $ countarray [0]; echo $ count. "
"; mysql_query (" UPDATE ". $ table_prefix." publica SET comment_count = '$ count' WHERE ID = '$ post_id' ");?>

You need to replace DB_HOST, DB_USER, DB_PASSWORD with your WordPress database host (usually localhost), database username and password.

You can find all of this information by logging into your WordPress hosting cPanel or by looking at your wp-config.php file using a file manager.

Once you've replaced the information, save this file as comentarios-fix.php on your desktop.

You will now need to upload this file to the root directory of your site. You can do this using an FTP client or by using the file manager in your web hosting control panel.

After uploading the file to your website, you need to open your web browser and access this file:

http://example.com/comments-fix.php

Replace example.com with your site address.

Visiting this file in your browser will run the script that simply loops through your posts, categories, tags, comments, etc. and will update the count.

How to fix category and number of comments after WordPress import

Important: Once you are done fixing your WordPress comment account, you need to remove comentarios-fix.php file from your server.

That's it, we hope this article helped you to update the number of comments after importing WordPress. You can also check out our guide on the most common WordPress errors and how to fix them.

If you enjoyed this article, please subscribe to our WordPress YouTube Channel video tutorials. You can also find us on Twitter and Google.+.