1

I just moved a site over from an old domain to a new domain (this means the server-side folder changes too).

I replaced all instances of the old domain in the database with the new domain and couldn't find any instances of the directory name. I checked that nowhere in the database the old domain or directory name are mentioned (at least not in plain text).

Various stuff inexplicably broke, one of them being all menus: They vanished (the theme has logic to hide the menus if they are empty, so maybe that was triggered). Deleting and recreating them worked, but I'd like to automate that.

Can someone explain to me how the menus depend on the domain in a way that doesn't show up in the database in plain-text? Is the url encoded somehow so my regular expressions don't find it?

1 Answer 1

0

When you do mysql query find and replace of strings in databases with wordpress, you can break the serialized data and essentially breaks the links between required tables and table columns.

Your only option is to restore the database before you ran those queries. In wp_options change ONLY the 'siteurl' and the 'home' url's to suit your new domain.

if you have hard coded links in your content and want to save time. you could try running:

UPDATE wp_posts
SET post_content= REPLACE(post_content, 'olddomain.com', 'newdomain.com');

UPDATE wp_posts
SET guid= REPLACE(guid, 'olddomain.com', 'newdomain.com');

That will take care of 99% of your old domain links without breaking your widgets or theme options. I would suggest manually editing your menu's, widgets and theme options from there which should not take you long with the content and media being updated with the above queries.

If you want to do it another way. You could restore the original database. Change the siteurl and home url's in wp_options. Once you get into wp-admin after that on the new domain.

You could use one of the following plugins which will keep serialized data in tact (apparently)

https://wordpress.org/plugins/better-search-replace/

https://wordpress.org/plugins/search-and-replace/

3
  • How is the data serialized? Then I can unserialize it and reserialize the changed content.
    – Nobody
    Commented Dec 7, 2019 at 14:46
  • Please see updated / edited answer above for plugin options to assist
    – Elgoots
    Commented Dec 7, 2019 at 14:58
  • The problem is that I asked question a and you answered question b. I looked up some more stuff and found out myself how the data is serialized, but I still don't know if the menus would keep working if I did a search and replace which is aware of the serialization issue.
    – Nobody
    Commented Dec 7, 2019 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.