WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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...
share|improve this question
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
up vote 1 down vote accepted

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);
share|improve this answer
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
Perfect. Thanks for the explanation. – N2Mystic Jul 6 '11 at 21:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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