Tjeneste-oppgradering: Følg linken for nærmere status vedrørende migrering, for generelle spørsmål og svar se vårt hjelpesenter.

How to update the WordPress database using search and replace?


EXPERIENCING PROBLEMS WITH OUR SERVICES? RUN A DIAGNOSE FIRST TO SAVE YOURS AND OUR TIME

Added: 03.10.2019 13:46:16     Last updated: 08.12.2020 08:56:39

This guide will show you two ways to update your database in WordPress.

 

Why update the WordPress database?

  • It is desirable to switch to www instead of no www or vice versa.
  • It is desirable to change to https from http.
  • The installation has been moved from a subdirectory or subdomain.
  • Updating SEO keywords.
  • Correct misspellings and typos.
  • Fix broken images or hard-coded links in the installation.
  • It is desirable to move from one domain name to another. Or from a temporary address, to the domain of the web hotel.
    For example, oldexampledomain.org to exampledomain.org.

 

Updating the database with a plugin

In this example we will update the WordPress database with a plugin. There are several plugins that do a "search and replace" in the database. Tn this example we have chosen to use the "Search & Replace" plugin.

In this example we will change the URLs in the database from:
https://www.exampledomain.org/oldwp to https://www.exampledomain.org/

In advance we have logged into WordPress backend (admin) and installed the plugin to be used.

Instructions:
Follow the instructions below to perform the search and replace in the database.
It is recommended to back up the WordPress installation before performing this.

  1. Click "Tools" in the menu on the left.
  2. Click "Search & Replace".
  3. Click "Search & Replace" in the menu at the top.
  4. Enter the old website address.
  5. Enter the new website address.
  6. Choose to perform search and replace for all tables in the database.
  7. Disable "Dry Run". If it is on, it will only check through the tables and not actually make the changes.
  8. Select the changes to be saved to the database in the web hosting.
  9. Click "Do Search & Replace" to make the changes.
Updating the WP database with a search and replace plugin

Finished
The WordPress database is now updated.
Tip! If the links on the website give an error message after the change, save the permalink again. Go to "Settings" and then "Permalink" in WordPress. Click "Save Changes."

 

Update database with WP-CLI

In this example we will update WordPress's database with WP-CLI in terminal.

In this example we will change the URLs in the database from:
https://www.exampledomain.org/oldwp to https://www.exampledomain.org/

In advance we have logged into WordPress backend (admin) and installed the plugin to be used.

Instructions:
Press that you understand the consequences of using the terminal and want to proceed.

  • Type "cd public_html" and press enter to get to the folder where WordPress is located.
  • Enter the command to do a search and replace in the database:
    wp search-replace 'exampledomain.org/oldwp' 'exampledomain.org/' --all-tables
    Press enter. Search and replace is completed.
Update WP using WP-CLI in the terminal

 

Finished
We have now updated the WordPress database using WP-CLI.