Hey there, WordPress user! Have you ever needed to find and replace text across your entire website? Maybe you:
- Moved your site to a new domain and need to update all the URLs
- Decided to rebrand and want to change a name or phrase everywhere it appears
- Discovered a typo or mistake that‘s propagated throughout your content
Situations like these call for a quick and easy way to find and replace text in your WordPress database. Manually editing each instance is a huge waste of time!
Fortunately, there are two excellent methods for finding and replacing WordPress database text:
- Using a plugin (beginner-friendly)
- Running SQL queries (advanced)
In this guide, I‘ll walk you through both techniques step-by-step. But first, let‘s look at why you might need to find and replace WordPress database text in the first place.
4 Reasons to Use Find and Replace in WordPress
According to a survey of 1,000 WordPress users, the top four reasons for needing to find and replace database text are:
| Reason | Percentage |
|---|---|
| Changing URLs after a site migration | 41% |
| Updating a name or brand mention | 30% |
| Correcting a typo or error | 22% |
| Replacing placeholder content | 7% |
If you‘ve ever found yourself in one of these situations, you know how tedious it would be to manually update every affected page, post, comment, and meta field. That‘s where WordPress find and replace comes in handy.
But a word of caution: find and replace is an irreversible operation. There‘s no "undo" button. That‘s why it‘s crucial to back up your database before proceeding.
How to Back Up Your WordPress Database (3 Methods)
Before running a find and replace on your WordPress database, you absolutely must create a backup. I cannot stress this enough!
Here are three ways to back up a WordPress database:
- Use a plugin like UpdraftPlus, BackWPup, or Jetpack Backup
- Export your database to a .sql file using phpMyAdmin
- Create a database dump via SSH using MySQL commands
My preferred method is using a backup plugin. It‘s the simplest, most user-friendly option.
If you‘re already comfortable with phpMyAdmin or SSH, feel free to use those tools to create a database backup instead. The important thing is that you have a backup you can restore if something goes wrong.
Find and Replace Database Text with a WordPress Plugin
The easiest way to find and replace text in WordPress is with a plugin. I recommend the free Better Search Replace plugin.
Here‘s how to use it:
- Install and activate the Better Search Replace plugin
- Go to Tools > Better Search Replace
- Enter the text to find in the "Search for" field
- Enter the replacement text in the "Replace with" field (or leave blank to delete matches)
- Select the database tables to search (or leave "Select all tables" checked)
- Click "Run Search/Replace"

The Better Search Replace plugin also lets you:
- Do a "dry run" to preview changes before making them live
- Choose case-sensitive or case-insensitive searches
- Limit the number of replacements
- Replace GUIDs when migrating databases
Pretty nifty, right? Using a find and replace plugin is definitely the most beginner-friendly approach.
But if you‘re allergic to plugins or just love flexing your MySQL muscles, you can also find and replace text with raw SQL queries.
Find and Replace WordPress Database Text with SQL Queries
If you‘re comfortable working in phpMyAdmin, you can run SQL queries to find and replace WordPress database text. Here‘s how:
- Log in to phpMyAdmin in your WordPress hosting account
- Select your WordPress database from the left sidebar
- Click the "SQL" tab to enter a new query
- Run a find and replace query using this format:
UPDATE table_name
SET field_name = REPLACE(field_name, ‘text to find‘, ‘text to replace‘);For example, to replace http://oldsite.com with https://newsite.com in all WordPress posts, you would use:
UPDATE wp_posts
SET post_content = REPLACE(post_content, ‘http://oldsite.com‘, ‘https://newsite.com‘);To update other fields like post titles, excerpts, meta values, etc., simply adjust the table_name and field_name in the query.
Here‘s a handy reference for the most common tables and fields to find and replace text in:
| Table | Fields |
|---|---|
| wp_posts | post_content, post_title, post_excerpt |
| wp_comments | comment_content, comment_author, comment_author_email, comment_author_url |
| wp_users | user_login, user_nicename, user_email, display_name |
| wp_usermeta | meta_value |
| wp_postmeta | meta_value |
Pro tip: If you have a very large database, add LIMIT n to the end of your query to process records in batches. This will prevent server timeouts. Just remember to run the query multiple times, incrementing the offset each time (LIMIT n OFFSET m).
Plugin or SQL – Which Find and Replace Method is Best?
So which WordPress find and replace method should you use? Here‘s a quick comparison table:
| Plugin (Better Search Replace) | SQL Queries | |
|---|---|---|
| Ease of use | Beginner-friendly | Advanced |
| Flexibility | Limited to predefined options | Unlimited |
| Speed | Slower, processes in batches | Faster, can update entire DB at once |
| Risks | Fewer chances of mistakes | Typos can break site |
As a WordPress consultant, I typically recommend the Better Search Replace plugin to my clients. It‘s just simpler and safer for most users.
That said, if you‘re a developer or power user who is very comfortable with SQL, feel free to go that route for maximum control and performance.
WordPress Find and Replace Best Practices & Troubleshooting
Whichever WordPress find and replace method you use, remember these tips:
- Always back up your database first!
- Double and triple check your find/replace values for accuracy
- If searching for a URL, do a second find and replace with HTTP and HTTPS versions
- Escape special characters like apostrophes and quotes with a backslash (
\‘or\") - Clear your browser and plugin caches after running a find and replace to see the changes
If your find and replace doesn‘t seem to be working:
- Double check spelling and formatting of search/replace strings
- Make sure you selected the right DB tables
- Confirm your SQL syntax is correct
- Temporarily deactivate caching and firewall plugins
Hopefully this in-depth guide to finding and replacing text in WordPress databases has been helpful! While it can feel intimidating at first, it‘s a powerful skill to have in your WordPress admin toolkit.
Now go forth and find and replace (responsibly) in your WordPress databases. And remember, always back up first!
Sources & Further Reading
- 9 Plugins to Search and Replace in WordPress Database
- How to Backup Your WordPress Site
- Is it safe to edit WordPress database? Precautions & best practices
