Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.