I'm trying to decontruct (and recreate) a serialized option value in wp_options called 'my_options'

How would I build the array to recreate this option_value that currently exists for 'my_options'?

update_option('my_options', ?)

After the update, the wp-options table would hold this value for 'my_options':

a:3:{s:12:"my_widget-1";a:2:{ etc...
  • 1
    unserialize, but you shouldn't need it as get_option() will do that for you... – onetrickpony Jul 6 '11 at 21:21
  • I'm placing it into the database for the first time. Its a one-time operation for presetting widget contents to a default starting point. Of course, after I've done that, I could call get_option as you suggest, but it won't be an option until I create it. – N2Mystic Jul 6 '11 at 21:23

You can't use it as-is because it will get double-serialized. So as per comment you unserialize it first and it will get serialized back when saved into option.

$array = unserialize( $stuff );
update_option('my_options', $array);
  • OK, so I just can't call update_uption('my_options','a:3:{s:12:"my_widget-1";a:2:{...etc') then right? – N2Mystic Jul 6 '11 at 21:32
  • @N2Mystic you can't. It will be treated like string and run through serialization again. – Rarst Jul 6 '11 at 21:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.