Unserialize, Serialize again and Update values

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.

Read More

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?

Related posts

Leave a Reply

1 comment

  1. 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 the new-domain , and then run these queries :

    /**
    To update WordPress options with the new blog location, use the following SQL command:
    **/
    
    UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-domain.com', 'http://www.new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
    
    /**
    After that you will need to fix URLs of the WordPress posts and pages, which translated from post slug, and stored in database wp_posts table as guid field. The URL values in this field are stored as abolute URLs instead of relative URLs, so it needs to be changed with the following SQL query:
    **/
    
    UPDATE wp_posts SET guid = replace(guid, 'http://www.old-domain.com','http://www.new-domain.com');
    
    /**
    If you have linked internally within blog posts or pages with absolute URLs, these links will point to wrong locations after you move the blog location. Use the following SQL commands to fix all internal links to own blog in all WordPress posts and pages:
    **/
    
    UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old-domain.com', 'http://www.new-domain.com');
    

    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() and update_post_meta() function which will take care of the serialization.