I've been building WordPress websites since 2006 and hadn't come across this one until today.
I would make changes to the Advanced CSS in the Theme Customizer and it would show in the preview window. I'd hit publish and everything looked normal, but when I refreshed the page, the changes weren't there.
I tried everything from How To Fix WordPress. I was using GeneratePress, but that didn't matter, because the problem was happening in TwentyTwenty also.
The problem kept happening, even with all the plugins deactivated and a default theme active.
I had just moved hosting, but it was to a server I already had sites on, so I knew the server was configured correctly.
Eventually I figured it out. When I moved hosts, for some reason the wp_options table (and a few of the others) didn't get a primary index set.
I wish I'd taken a screenshot of the before as I can't recreate it now.
When I turned debugging on, every time I tried to make changes I got a bunch of notices that said "PHP Notice: Trying to get property 'post_type' of non-object".
Each line referenced a different file, like /wp-includes/class-wp-query.php or /wp-includes/post.php with different line numbers. Going to them didn't shed much light on the root cause.
When I went to the wp_options table in phpMyAdmin I got the error message: "This table does not contain a unique column. Grid edit, checkbox, Edit, Copy and Delete features are not available". This error means you don't have a unique primary key set. See below for the fix.
How to fix Theme Customizer Not Saving
- Check if there is a problem with the theme or the plugins,
- Make sure you don't have any errors in your CSS preventing it from saving,
- Check that your wp_options table is correctly structured with a primary index.
This is how the wp_options table should be structured:
My wp_options table was missing the primary key.
To add a primary key,
- Open your database in phpMyAdmin
- Go to wp_options
- Go to the "Structure" tab
- Hover over the "More" link on the option_id row
- Click "Primary"
Now you should be able to save changes made in the theme customizer.
When you click "Primary", you may get an error that says "duplicate key 0 for primary". That means you have two or more rows in the table that have "0" as their ID.
It is because you were operating the site without a primary key set and it threw everything into an ID of 0. To fix it, either delete those rows, or if you have a copy of the table, you might want to drop the contents of that table and re-upload.
I had that problem and ended up just dropping everything and restarting and the site is now working properly.
I figure it's because the database ran into issues when I was importing the old table and it didn't get around to running the primary key changes on some of the tables.
Hopefully this can save you from the hours of frustration I just went through.