Reputation: 1586
I'm trying to migrate an existing wordpress with a theme customized by the customizer. I can get the wordpress up and running, but all of the theme customization has disappeared. I narrowed the problem to the customizer and the wp-options table in the database. There the option_value for the option theme_mods_{theme-name} is reset whenever I visit/reload the website. If I make changes via the customizer, they do appear, but if I change the value of the option_value within the database, the entire theme customization is removed.
I'm using a wordpress hosted on IIS, database is a MySql 5.x (don't know the exact version).
Upvotes: 2
Views: 1380
Reputation: 44
Manu's answer is the right one. I may add a small advice : updating serialized data via a sql request is a brain-burner. The only reasonable way to do it is to use wp-cli search-replace tool.
Search/replace intelligently handles PHP serialized data, and does not change primary key values. https://developer.wordpress.org/cli/commands/search-replace/
Upvotes: 1
Reputation: 46
Okay, I've been facing this issue for a while and finally solved it. This anwser put me on the track : Showing default theme when uploading WordPress website on server
When you migrated you probably changed the URL through your SQL file using find & replace. The thing is that the theme_mods_{theme-name}
entry in the wp_options table is encoded as an object with this format : type:length:value
So, changing the value of one option, you might change his length too. If the length is not matching the value, WP will consider this object as invalid and will reset the option to the default a:1:{s:18:"custom_css_post_id";i:-1;}
, breaking your menus and other customized options.
Example:
Working on localhost:
a:4:{s:18:"custom_css_post_id";i:-1;s:18:"nav_menu_locations";a:5:{s:6:"menu-1";i:1120;s:6:"menu-2";i:1125;s:8:"top-menu";i:1120;s:8:"footer-1";i:1120;s:8:"footer-2";i:1125;}s:9:"my_option";s:29:"Lorem ipsum";s:15:"posts_row_image";s:32:"http://localhost/lorem/dolor.png";}
Invalid on distant server:
a:4:{s:18:"custom_css_post_id";i:-1;s:18:"nav_menu_locations";a:5:{s:6:"menu-1";i:1120;s:6:"menu-2";i:1125;s:8:"top-menu";i:1120;s:8:"footer-1";i:1120;s:8:"footer-2";i:1125;}s:9:"my_option";s:29:"Lorem ipsum";s:15:"posts_row_image";s:32:"http://mydistantwebsite.com/lorem/dolor.png";}
Corrected length, working on distant server:
a:4:{s:18:"custom_css_post_id";i:-1;s:18:"nav_menu_locations";a:5:{s:6:"menu-1";i:1120;s:6:"menu-2";i:1125;s:8:"top-menu";i:1120;s:8:"footer-1";i:1120;s:8:"footer-2";i:1125;}s:9:"my_option";s:29:"Lorem ipsum";s:15:"posts_row_image";s:43:"http://mydistantwebsite.com/lorem/dolor.png";}
Upvotes: 3