WordPressで検索と置換を行いたいですか?最近、あるユーザーから、SQLコードを書いたりphpMyAdminを使ったりせずにWordPressデータベース上で検索と置換を実行する方法を尋ねられました。多くの初心者はコードを書くのが苦手なので、WordPress用の検索置換プラグインを見つけました。この投稿では、WordPressで検索と置換を行う方法を紹介します。
はじめに
WordPressのデータベースに変更を加える前に、WordPressの完全なバックアップを作成することが非常に重要です。
このベストプラクティスを習慣にしてください。WordPressのデータベースに直接変更を加えているときは、いつでも物事がうまくいかない可能性があります。バックアップがあれば、何も失うことなくWordPressサイトを簡単に復元することができます。
WordPress用Better Search and Replaceのインストールと使い方
まず最初に、Better Search Replaceプラグインをインストールして有効化します。有効化したら、Tools ” Better Search Replaceのページでプラグインを使用する必要があります。
検索したい文字列を追加し、置換テキストを追加するだけです。
その後、検索したいテーブルを選択します。例えば、投稿カテゴリー内のテキストを検索・置換したい場合は、投稿テーブルを選択します。複数のテーブルを選択することもできます。
WordPressのデータベース管理と各テーブルの役割については、さらに詳しくご覧ください。
プラグインは大文字と小文字を区別して検索と置換を実行できます。また、実際にテキストを置換することなく、検索によってどれだけのセルが影響を受けるかを確認できるドライランを実行することもできます。
問題がなければ、検索・置換の実行ボタンをクリックしてください。ドライランオプションにチェックを入れなかった場合、プラグインはWordPressデータベース上で検索と置換を実行します。
トラブルシューティング
検索と置換の実行中に白い画面が表示されたり、タイムアウトになることがあります。プラグインページの設定タブをクリックしてください。
最大ページサイズオプションが表示されます。タイムアウトや白い画面を避けるために、ページサイズを小さくしてみてください。
以上、この投稿がWordPressデータベース用のより良い検索置換プラグインを見つける手助けになれば幸いです。WordPressデータベースをクリーンアップしてパフォーマンスを向上させる方法についてのチュートリアルもご覧ください。
この投稿が気に入った場合は、WordPressの動画チュートリアルのYouTubeチャンネルを購読してください。Twitterや Facebookでも私たちを見つけることができます。
Daniel
Does the plugin work for bbpress topics and replies too?
WPBeginner Support
The plugin does have the ability to search what was added through other plugins, you would mainly want to make ensure you search the correct tables.
管理者
Paul G
Thanks, this mostly worked for me but didn’t quite change all of the image links.
The rest I could easily change myself by editing the custom modules.
WPBeginner Support
Glad our guide was helpful
管理者
Karol
Changed a website from http to https via cpanel; green lock did not appear and “connection is not secure” warning was present. This plugin worked great for me. The only difference I did was that I left the checkmark off “Case Insensitive?”.
Every site can be different with it’s own hurdles to jump through but the dry run seemed to look okay without any errors so I ran with it. Green lock appeared right away for the site. Plugin worked for me. I hope it continues to work with other sites.
My only question now is … Do I leave the Better Search Replace plugin installed and activated or do I uninstall it now that I’m done?
WPBeginner Support
That would be a personal preference question but you should be able to remove the plugin without worry
管理者
Mandy
Hello,
My site is having issues showing images lately, and my host said that it’s because the paths are wrong. They recommended this plug in, but my problem is that I am not sure what I am searching and replacing. Here’s why:
When I insert an image in “visual” mode within a post, it shows up. They all do.
Then when I preview or publish, some images don’t show up. What I am noticing lately is that instead of the code showing them as “image.jpg”, they now have the image size you choose in the path – “image-300×188.jpg” (this happens to be the medium size for this particular image). Why is it putting the pixel dimensions? If none of the images worked, I could say yes, the paths are incorrect, but some images DO work! I am officially bamboozled. It seems so random.
Best,
Mandy
WPBeginner Support
Hi Mandy,
Please take a look at our guide on how to fix common image issues in WordPress.
管理者
Ashraf Ali
I am switching from http to https now the common problem faced is broken css, I am wondering if could use this plugin to replace https:// to just //
So that all contents are delivered over https
Cheers
Drew
I had a program enter structured data that is all different. I want to remove everything between and including this : ———————-
How would I do that?
WPBeginner Support
Hi Drew,
We are not sure we completely understand your issue. However, we are guessing that you had a plugin to add structured data and now you want to remove the structured data from your WordPress posts and pages? If this is the case, then you can simply uninstall the plugin.
管理者
Sueli
Great plugin!
I have a question.
Can I use a wildcard?
I am trying to remove numbers added after an image file. They are different (both the numbers and their length). The stop point would be the (“).
Some examples of what I want to replace with (jpg”)
(jpg?11906004322295206140″)
(jpg?15231215847335105667″)
(jpg?82668654789154738″)
Is it possible with this plugin?
Thanks
David
I download “Better Search & Replace. Once it found entries, it doesn’t show me unless I buy premium addon.
So instead I ditched that and downloaded “Search & Replace”. It took me only two minutes to replace 100 entries.
Ralpheal
Wow thanks so much, this is truly a luxury. Going to save me a lot of time, as I was considering changing a phone number on 1oo’s of blog posts.
Thanks so much,
Ralpheal
Mike
This plugin did not work for me. I backed up the database, then unchecked “Dry Run”. It messed up things all over the site and there was no way to undo the changes.
I even tried to restore the database backup I created with it before making changes and that didn’t work. Don’t use this unless you’re prepared to do an entire site restoration.
WPBeginner Support
You should have tested with dry run first to see how many rows are affected by the plugin. Glad that you followed the instructions and made a backup first.
管理者
vikas kumar
sir
help me out from pagination error i did which you show in video but i didn’t get result
i am using macbook air in this your given shortcode not work properly
Marko Tiosavljevic
yes, but this plugin is practically useless when it comes to migrations.
When you migrate website from domain . com to another . com you need to change
you need to connect to database for changing url or you need to insert it in wp_config as url
i am working on external app wp safe mode that is solving this problems in best way.
WPBeginner Support
It is highly useful in performing search and replace after you have connected to the WordPress database.
管理者
Nico
Hi, it seems that this plugin is no longer available in Wordpress Plugin Directory. Which alternative plugin do you recommend?
With kind regars,
Nico.
Syed Umair Umar
Better Search and Replace is an alternate for me. The editorial staff of WP Beginner seems too lazy and replies to comments very few times.
WPBeginner Support
Thanks for helping out.
管理者
Brian
Does this take into account serialize data or will it break plugins that use serialized metadata? I know of a few plugins that do this for migration purposes. If it doesn’t it could cause more problems than it solves.