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 am writing a plugin and it require around 15 different options so I am using php serialization. I'm doing it by an array and update option with php serialize functions.

but when I access it from /wp-admin/options.php I'm able to see the raw data but while as core wordpress options are locked mentioned SERIALIZED DATA. I want to implement something like this.

share|improve this question
    
How are you saving that data, and again how are you fetching it, and what does the structure of the data you're saving look like(ie. how is it defined).. In short, post the applicable code please. –  Mark Duncan Aug 2 '11 at 15:50

1 Answer 1

The correct way to store multiple options is as a multidimensional array and save to one option field.

$myopt = array(
    'variable1' => ...
    'variable2' => ...
    ....
);

Then simply pass the array to update_option()

update_option('my_settings_field', $myopt);

If you pass an array WP will auto serialize the data for you.

Then to read back out:

$myopt = get_option('my_settings_field');

WP will auto un-serialize the data and put back into an array.

You mentioned that on options.php you see that the option is shown as SERIALIZED DATA this is because you cannot reliably edit serialized data as a string. If you want to be able to edit your options from the options.php page then you will need to save each option individually. I would not recommend this. What I recommend is that you create your own options page for editing your options. There are a number of tutorials out there that can get you started.

http://codex.wordpress.org/Creating_Options_Pages

Is a good starting point. And also check out Settings API

share|improve this answer
    
Thanks @Brady it helps fo me :) –  Fresher Sep 26 '13 at 10:23

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.