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

WordPressインポート後にカテゴリーとコメント数を修正する方法

WordPressサイトをインポートすると、カテゴリーやコメント数に問題が生じることがあります。せっかくインポートしたのに、不正確な数字が表示されるのは悔しいものです。

良いニュースは、これらの問題を解決する簡単な方法があることだ。

この投稿では、WordPressインポート後にカテゴリーとコメント数を修正する方法をご紹介します。あなたのサイトを元に戻しましょう!

How to Fix category and comment count after WordPress import

WordPressのカテゴリーとコンテンツ数のエラーの原因は?

ビルトインを使ってWordPressサイトをインポートすると、コメント数が不正確に表示されたり、まったく表示されないことがあります。

すべてのコメントは安全にインポートされ、管理エリアでも表示されますが、投稿日: のカウントがサイト上で正しく表示されない場合があります。この同じインポートエラーは、カテゴリーやカスタマタクソノミーのカウントにも影響します。

Fix comment count preview

上のスクリーンショットでお気づきのように、インポート後、コメントする数とカテゴリー数が実際の数ではなく0と表示されています。

以下では、この問題を解決し、WordPressで正確なコメント数を表示する方法を見ていきましょう。

WordPressでカテゴリーとコメント数を修正する

作業を始める前に、サイトのWordPressバックアップを作成しておきましょう。サイトに大きな変更を加える前に、毎回これを行う必要があります。

Duplicatorの使用をお勧めするのは、市場で最も包括的なWordPressバックアッププラグインだからです。

詳しくは、DuplicatorでWordPressサイトをバックアップする方法をご覧ください。

バックアップを作成したら、次のステップに進みましょう。メモ帳のようなプレーンテキストエディターを開き、以下のコードをコピー&ペーストする必要があります:

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

次に、DB_HOST、DB_USER、DB_PASSWORDをWordPressデータベースのホスティングサービス(通常はlocalhost)、データベースのユーザー名、パスワードに置き換えることを忘れないでください。

WordPressホスティングサービスのコントロールパネルにログインするか、ファイルマネージャーを使ってwp-config.phpファイルを見れば、これらの情報をすべて見つけることができます。

情報を置き換えたら、そのファイルをcomments-fix.phpとしてデスクトップに保存します。

このファイルをサイトのルートディレクトリにアップロードする必要があります。FTPクライアントまたは ウェブホスティングサービスコントロールパネルのファイルマネージャを使用して行うことができます

詳しくはFTPを使ってWordPressにファイルをアップロードするステップバイステップガイドをご覧ください

ファイルをサイトにアップロードしたら、ウェブブラウザーを開いてこのファイルにアクセスしてみよう:

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

example.comをあなたのサイトのアドレスに置き換えることをお忘れなく。

ブラウザーでこのファイルにアクセスすると、スクリプトが実行されます。投稿、カテゴリー、タグ、コメントをループしてカウントを更新します。

Comment count fix

WordPressのコメント数を修正し終わったら、サーバーからcomments-fix.phpファイルを削除する必要があります。

ボーナスヒントその他のコメントする設定

WordPressサイトをインポートした後、コメント設定を再度行ってください。

まず、初期設定で新規投稿にコメントすることを許可するかどうかを決めましょう。または、個々の投稿に対してコメントを有効化または無効化することもできます。

モデレーション設定は、コメントする品質をコントロールするのに役立ちます。コメントを手動で承認するか、信頼できるユーザーからのコメントが自動的に表示されるようにするかを選択できます。

Opening the Thrive Comments Moderation page on WordPress

メール通知機能でコメントするたびに更新されます。誰かがコメントした時や、コメントの承認が必要な時に通知を受け取ることができます。モデレーションを有効化すると、コメントが承認されたときにユーザーに通知することもできます。

WordPressダッシュボードの設定 ディスカッションからコメントする設定を行うことができます。しかし、より高度な機能のためにThrive Commentsを使用することをお勧めします。

Thrive Comment's homepage

Thrive Commentsは市場で最高のWordPressコメントプラグインです。基本的な設定に加え、アップヴォート、ダウンヴォート、いいね!、バッジ、ソーシャルメディア共有などの機能で読者を惹きつけることができます。

詳しくはスライブのレビューをご覧ください。

この投稿が、WordPressインポート後にカテゴリーとコメント数を修正する方法を学ぶのにお役に立てば幸いです。次に、WordPressテーマのトップページにコメントを表示する方法や、WordPressのカテゴリー順を変更する方法についてのガイドもご覧ください。

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

情報開示 私たちのコンテンツは読者支援型です。これは、あなたが私たちのリンクの一部をクリックした場合、私たちはコミッションを得ることができることを意味します。 WPBeginnerの資金源 をご覧ください。3$編集プロセスをご覧ください。

アバター

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.

究極のWordPressツールキット

ツールキットへの無料アクセス - すべてのプロフェッショナルが持つべきWordPress関連製品とリソースのコレクション!

Reader Interactions

22件のコメント返信を残す

  1. Syed Balkhi

    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

    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

      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.

      管理者

  3. Carlos

    Thanks for this tutorial! Once I switched to PHP 5.5 the script worked like a charm.

    • WPBeginner Support

      Glad it worked for you :)

      管理者

  4. Peter Edwards

    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

      Ooo, such a simple solution, and it worked! Thanks!

  5. Kingsley Felix

    anyone for duplicate comments?

  6. Pare

    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.

  7. Phuc

    I get an error 500 if I want to access the comments-fix.php file. How can I fix this?

  8. Jay

    To echo Yuriy’s comments, it’s not working for me either with PHP 7. 500 error.

  9. Yuriy Smirnov

    Doesn’t work on php7, because mysql_connect function has been removed since 7.0.0 verstion.

  10. Rianta D. Mulyana

    Thanks brother, it works!

  11. Cosmin

    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

      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.

  12. Makinde

    Thanks WPBeginner, This was helpful..

    Thanks for always being there for us.

    Appreciate!

  13. Aeryn Lynne

    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.

  14. Naki Biga

    Work like a charm, thank you very much!

    Very simple and usefull code!

  15. Edwin Rio

    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 !

  16. union

    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 !

  17. Connor Rickett

    That seems fairly straightforward. Thanks for putting that code together, that’s a huge help!

返信を残す

コメントありがとうございます。すべてのコメントは私たちのコメントポリシーに従ってモデレートされ、あなたのメールアドレスが公開されることはありませんのでご留意ください。名前欄にキーワードを使用しないでください。個人的で有意義な会話をしましょう。