Search code examples
phpmysqlwordpressbackupstaging

Copy Wordpress to Staging losing wp_options


I'm copying wordpress from my production to my staging site.

I do this by:

  1. copying all files
  2. making a mysql dump
  3. importing mysql dump
  4. updating urls in the database with:

Statements:

UPDATE wp_options SET option_value = REPLACE(option_value, 'http://www.domain.de', 'http://staging.domain.de');

UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'http://www.domain.de', 'http://staging.domain.de');

UPDATE wp_posts SET guid = REPLACE(guid, 'http://www.dailycat.de', 'http://staging.domain.de');

UPDATE wp_posts SET post_content = REPLACE(post_content, 'http://www.domain.de', 'http://staging.domain.de');

Doing this, some of the setting of e.g. the theme, widgets and mailchimp are lost. They are still in the database but they are not showing up on the screens. Any idea how to fix this?

Thanks and I really appreciate your help!


Solution

  • You need to use a script that correctly deserializes/reserializes data in the database, such as serialized data for theme options, widget content, etc. Those UPDATEcommands run in the database won't do that; they do a simple find/replace, which breaks serialized data.

    Use interconnectit.com WordPress Serialized PHP Search Replace Tool

    Bear in mind that some themes don't correctly serialize data in the first place, so depending on your theme, the script may not fully work, and you may need to reset some theme options, widgets, etc, anyway.

    Also see Moving WordPress « WordPress Codex