Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
Coppa WPB
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

Come correggere il conteggio delle categorie e dei commenti dopo l’importazione di WordPress

Nota editoriale: guadagniamo una commissione dai link dei partner su WPBeginner. Le commissioni non influenzano le opinioni o le valutazioni dei nostri redattori. Per saperne di più su Processo editoriale.

Avete notato un conteggio dei commenti errato dopo aver importato il vostro sito WordPress?

L’importazione di un sito WordPress utilizzando l’importatore incorporato può a volte incasinare il conteggio dei commenti di WordPress.

In questo articolo vi mostreremo come correggere il conteggio delle categorie e dei commenti dopo l’importazione di WordPress.

How to Fix category and comment count after WordPress import

Cosa causa l’errore di conteggio delle categorie e dei contenuti in WordPress?

Quando importate il vostro sito WordPress utilizzando l’importatore integrato, a volte il conteggio dei commenti è impreciso o inesistente.

Mentre tutti i commenti di WordPress sono importati in modo sicuro e visibili nell’area di amministrazione, i post mostreranno un conteggio dei commenti errato sul sito web. Questo stesso errore di importazione può avere un impatto anche sul conteggio delle categorie e delle tassonomie personalizzate.

Fix comment count preview

Come avete notato nella schermata precedente, dopo l’importazione il conteggio dei commenti e delle categorie mostra 0 invece del numero effettivo.

Detto questo, vediamo come risolvere questo problema e vedere il conteggio accurato dei commenti in WordPress.

Correggere il conteggio delle categorie e dei commenti in WordPress

Innanzitutto, è necessario creare un backup completo del sito WordPress. Dovreste farlo ogni volta prima di eseguire una modifica importante sul vostro sito.

Consigliamo di utilizzare Duplicator perché è il plugin di backup per WordPress più completo sul mercato.

Per maggiori dettagli, consultate questa guida su come eseguire il backup del vostro sito WordPress con Duplicator.

Una volta effettuato il backup, passiamo alla fase successiva.

Quindi, aprire un editor di testo semplice come Notepad e copiare e incollare il codice seguente:

<?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'");
        }
?>

È necessario sostituire DB_HOST, DB_USER, DB_PASSWORD con l’host del database di WordPress (di solito localhost), il nome utente e la password del database.

Potete trovare tutte queste informazioni accedendo al cPanel del vostro hosting WordPress o consultando il file wp-config.php con un file manager.

Una volta sostituite le informazioni, salvare il file come comments-fix.php sul desktop.

Ora è necessario caricare questo file nella directory principale del sito. È possibile farlo utilizzando un client FTP o il file manager del pannello di controllo del web hosting.

Per maggiori informazioni, seguite la nostra guida passo-passo su come usare FTP per caricare file su WordPress.

Dopo aver caricato il file sul vostro sito web, dovete aprire il vostro browser web e accedere a questo file:

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

Sostituite example.com con l’indirizzo del vostro sito.

Se si visita questo file nel browser, viene eseguito lo script che si limita a scorrere i post, le categorie, i tag, i commenti e ad aggiornare il conteggio.

Comment count fix

Importante: Una volta terminata la correzione del numero di commenti su WordPress, è necessario eliminare il file comments-fix.php dal server.

Speriamo che questo articolo vi abbia aiutato a capire come correggere il conteggio delle categorie e dei commenti dopo l’importazione di WordPress. Potreste anche voler dare un’occhiata alla nostra guida su come risolvere gli errori più comuni di WordPress e alla nostra guida definitiva sulla SEO di WordPress per migliorare le vostre classifiche.

Se questo articolo vi è piaciuto, iscrivetevi al nostro canale YouTube per le esercitazioni video su WordPress. Potete trovarci anche su Twitter e Facebook.

Divulgazione: I nostri contenuti sono sostenuti dai lettori. Ciò significa che se cliccate su alcuni dei nostri link, potremmo guadagnare una commissione. Vedi come WPBeginner è finanziato , perché è importante e come puoi sostenerci. Ecco il nostro processo editoriale .

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

Il kit di strumenti WordPress definitivo

Ottenete l'accesso gratuito al nostro kit di strumenti - una raccolta di prodotti e risorse relative a WordPress che ogni professionista dovrebbe avere!

Reader Interactions

22 commentiLascia una risposta

  1. 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!

  2. 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

  3. 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?

  4. 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.

  5. 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.

  6. 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.

  7. 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 !

  8. 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 !

Lascia una risposta

Grazie per aver scelto di lasciare un commento. Tenga presente che tutti i commenti sono moderati in base alle nostre politica dei commenti e il suo indirizzo e-mail NON sarà pubblicato. Si prega di NON utilizzare parole chiave nel campo del nome. Avremo una conversazione personale e significativa.