I’m working on a migrated WordPress, site url changed, everything works fine except some serialized data stored by a plugin.
The data is stored in the wp_options table, in the option_value column, for each record that the plugin saved.
So the data is still there, the problem is that when the url changed, it didnt get re-serialized (the count of the string content still thinks it’s the old url lenght), therefore the plugin isn’t working properly.
So, to find exactly the records that need to be updated, I use
$t1 = $wpdb->prefix . "vslider";
$t2 = $wpdb->prefix . "options";
$records_ineed = $wpdb->get_results("SELECT * FROM '".$t1."', '".$t2."' WHERE '".$t1."'.option_name='".$t2."'.option_name");
That gives me exactly the records that I need to re-serialize (it matches the name of the record created in the plugin table, with the record created in the wp_option table)
What do I do now?!
How do I take only the option_value of each, unserialize it, reserialize it and update the existing value in the db?
Should I save the reserialized values to a new table, and then replace from that table back to wp_options? How?
Otherwise what are other solutions?
There is no need to do that , what you need is to import the value as – is . it is an array and it will work fine as such as long as you do not alter the data in any way.
At any event , when you import migrate a wp site to another URL , there is absolutely no need to read the wp-options table´s columns one-by-one .
What you need to do it just dump your SQL from the Original (
old-domain
) site , then import into thenew-domain
, and then run these queries :Just for verification , after running those commands , go back to the options table and verify that your home and site_url functions are both correct as for the
new-domain
data.If you do still want , for some obscure reason, insert data directly into the options table manually ( ?? why ) then you should consider using
get_post_meta()
andupdate_post_meta()
function which will take care of the serialization.