Stellen Sie fest, dass die Anzahl der Kommentare nach dem Import Ihrer WordPress-Website nicht korrekt ist?
Beim Importieren einer WordPress-Website mit dem eingebauten Importer kann die Anzahl der WordPress-Kommentare manchmal durcheinander geraten.
In diesem Artikel zeigen wir Ihnen, wie Sie die Anzahl der Kategorien und Kommentare nach dem Import von WordPress korrigieren können.
Was verursacht den Kategorie- und Inhaltszählungsfehler in WordPress?
Wenn Sie Ihre WordPress-Website mit dem integrierten Importer importieren, kann es vorkommen, dass die Anzahl der Kommentare ungenau oder gar nicht angezeigt wird.
Während alle WordPress-Kommentare sicher importiert werden und im Verwaltungsbereich sichtbar sind, wird auf Ihrer Website eine falsche Anzahl von Kommentaren angezeigt. Der gleiche Importfehler kann sich auch auf die Anzahl der Kategorien und benutzerdefinierten Taxonomien auswirken.
Wie Sie im obigen Screenshot sehen können, werden nach dem Import die Anzahl der Kommentare und Kategorien mit 0 angezeigt, anstatt der tatsächlichen Anzahl.
Schauen wir uns also an, wie man dieses Problem beheben und die genaue Anzahl der Kommentare in WordPress anzeigen kann.
Korrektur der Kategorie- und Kommentaranzahl in WordPress
Zunächst müssen Sie eine vollständige WordPress-Sicherung Ihrer Website erstellen. Dies sollten Sie jedes Mal tun, bevor Sie eine größere Änderung an Ihrer Website vornehmen.
Wir empfehlen die Verwendung von Duplicator, weil es das umfassendste WordPress-Backup-Plugin auf dem Markt ist.
Weitere Einzelheiten finden Sie in dieser Anleitung zur Sicherung Ihrer WordPress-Website mit Duplicator.
Sobald Sie die Sicherung durchgeführt haben, können Sie zum nächsten Schritt übergehen.
Öffnen Sie als Nächstes einen einfachen Texteditor wie Notepad und kopieren Sie den folgenden Code und fügen Sie ihn ein:
<?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'];
echo "term_taxonomy_id: ".$term_taxonomy_id." count = ";
$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];
echo $count."<br />";
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'];
echo "post_id: ".$post_id." count = ";
$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];
echo $count."<br />";
mysqli_query($myConnection, "UPDATE ".$table_prefix."posts SET comment_count = '$count' WHERE ID = '$post_id'");
}
?>
Ersetzen Sie DB_HOST, DB_USER, DB_PASSWORD durch den Host Ihrer WordPress-Datenbank (in der Regel der localhost), den Benutzernamen und das Passwort der Datenbank.
Sie finden all diese Informationen, indem Sie sich in das cPanel Ihres WordPress-Hostings einloggen oder die Datei wp-config.php mit einem Dateimanager ansehen.
Sobald Sie die Informationen ersetzt haben, speichern Sie diese Datei als comments-fix.php
auf Ihrem Desktop.
Nun müssen Sie diese Datei in das Stammverzeichnis Ihrer Website hochladen. Dazu können Sie einen FTP-Client oder den Dateimanager in Ihrem Webhosting-Kontrollzentrum verwenden.
Weitere Informationen finden Sie in unserer Schritt-für-Schritt-Anleitung zum Hochladen von Dateien in WordPress per FTP.
Nachdem Sie die Datei auf Ihre Website hochgeladen haben, müssen Sie Ihren Webbrowser öffnen und zu dieser Datei gehen:
https://example.com/comments-fix.php
Ersetzen Sie example.com
durch die Adresse Ihrer Website.
Wenn Sie diese Datei in Ihrem Browser aufrufen, wird das Skript ausgeführt, das Ihre Beiträge, Kategorien, Tags und Kommentare in einer Schleife durchgeht und die Anzahl aktualisiert.
Wichtig! Sobald Sie mit der Korrektur der WordPress-Kommentaranzahl fertig sind, müssen Sie die Datei comments-fix.php
von Ihrem Server löschen.
Wir hoffen, dass dieser Artikel Ihnen geholfen hat zu erfahren, wie Sie die Anzahl der Kategorien und Kommentare nach einem WordPress-Import korrigieren können. Vielleicht möchten Sie auch unseren Leitfaden zur Lösung der häufigsten WordPress-Fehler und unseren ultimativen WordPress-SEO-Leitfaden zur Verbesserung Ihrer Rankings lesen.
Wenn Ihnen dieser Artikel gefallen hat, dann abonnieren Sie bitte unseren YouTube-Kanal für WordPress-Videotutorials. Sie können uns auch auf Twitter und Facebook finden.
Syed Balkhi says
Hey WPBeginner readers,
Did you know you can win exciting prizes by commenting on WPBeginner?
Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
You can get more details about the contest from here.
Start sharing your thoughts below to stand a chance to win!
Fitri says
Mine is not working, all the count from comments-fix.php is appear, but when i go to single page product it still says Reviews(0)
WPBeginner Support says
Your server may be running on a newer PHP version, this code was for php 5.5 and we will certainly take a look into what we can do to update the code.
Admin
Carlos says
Thanks for this tutorial! Once I switched to PHP 5.5 the script worked like a charm.
WPBeginner Support says
Glad it worked for you
Admin
Peter Edwards says
I lost most of the tag counts in a recent import – fixed this by bulk editing all the posts which were tagged and clicking update (without any changes). This triggers the tag count to be updated by wordpress core. Not sure if a similar trick would work for comments?
Bonnie says
Ooo, such a simple solution, and it worked! Thanks!
Kingsley Felix says
anyone for duplicate comments?
Pare says
Just using cPanel go to PhpMyAdmin
Check What is category id (term_id) in table „xxx_terms“ and then update count value in column count into the table „xxx_term_taxonomy“ where the term_id is equal term_id of xxx_terms table which that category exists on.
Forexample „uncategory“ of product is term_id = 10 and count value is wrong, I update count value to be correct number in table „xxx_term_taxonomy“ where term_id = 10. by manual on cPanel – PhpMyAdmin tool.
Phuc says
I get an error 500 if I want to access the comments-fix.php file. How can I fix this?
WPBeginner Support says
Hello,
Please see our guide on how to fix 500 internal server error.
Admin
Jay says
To echo Yuriy’s comments, it’s not working for me either with PHP 7. 500 error.
Yuriy Smirnov says
Doesn’t work on php7, because mysql_connect function has been removed since 7.0.0 verstion.
Rianta D. Mulyana says
Thanks brother, it works!
Cosmin says
Quick question: when replacing the DB_HOST, DB_USER, DB_PASSWORD and DB_NAME do we need to use „“ or “ to enclose those values in? Or do we simply paste the values?
I tried and I am getting 500 Internal Server Error while accessing the uploaded file
Tyler says
Yes, you do need to include single quotes around those values. Author should update the snippet to reflect that. Also, author forgot to mention that DB_NAME must also be changed.
Easy to spot, but this tutorial will fail for anyone following the instructions explicitly.
Makinde says
Thanks WPBeginner, This was helpful..
Thanks for always being there for us.
Appreciate!
Aeryn Lynne says
After a disastrous comment import that involved Intense Debate (only thing we could do is import bits of the xml file directly into mysql after obtaining post IDs for nearly a thousand posts,) I’m definitely in need of a quick program like this to correct the count, so thank you!
If anyone is looking to fix the comment count for one or two posts only though: instead of accessing FTP and mysql, they just need click Edit on one of the comments of the post that needs correction, and then click Update, and the post then updates the comment count for all comments involved in that post.
Naki Biga says
Work like a charm, thank you very much!
Very simple and usefull code!
Edwin Rio says
hi …
i have migrated one sito into another (i was using disqus for comments)
now in my new site, i can see the comments on the comments area but once i activate the disqus plugin the comments are not appearing on the front end article,
is this solution for my problem as well or my problems its most on disqus side ?
Thanks !
union says
hi …
i have migrated one sito into another (i was using disqus for comments)
now in my new site, i can see the comments on the comments area but once i activate the disqus plugin the comments are not appearing on the front end article,
is this solution for my problem as well or my problems its most on disqus side ?
Thanks !
Connor Rickett says
That seems fairly straightforward. Thanks for putting that code together, that’s a huge help!