moving wordpress and correcting the new file paths

I followed the method listed on the wordpress codex Moving WordPress and everything went smoothly. Except my images were not visible. All my images where hardcoded in using custom fields with relative urls. eg:

So the problem was the image path needed to be changed on each individual post. Changing 187 image paths manually is time intensive. I try to avoid manual alterations like this and went searching for a more dynamic way.

Here is that dynamic way.

Access your database via php myAdmin. Click the SQL button. Now do a SQL find and replace using the below code.

Find and replace meta data in the mysql database.

As i mentioned before. I use custom fields for all my image paths.

So all my image paths are in the table “wp_postmeta” table of the database. Therefore, my script looked like this.

Heres a couple more handy scripts.

Find and Replace hardcoded image paths in the wordpress content area

This script will alter all the occurrences of “http://www.old.com” to “http://new.com/”.

Filter the tables

While we are at it. here is a handy one to filter the db to display only the post tables with a post type of page

select all woocommerce orders

update values in wp options

Select all tables from the guid column that contain the string “localhost”

move all woocommerce orders to the trash

Select posts by id

Remove data from a table

Comments are closed.