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 checking out how a particular plugin works and noticed that it stores its data for option_value in wp_options in this array format...


I like this method, since it only uses a single row to hold my custom data, uninstall cleanup is easy. Is there a standard way to do a get/set operation on a custom field that results in this syntax?

Update: Thanks to Denis and the others who've added responses.

Here's an excellent tutorial on this method in case anyone else has this question > http://striderweb.com/nerdaphernalia/2008/07/consolidate-options-with-arrays/

share|improve this question
up vote 5 down vote accepted

Just pass an array when updating your option. It'll then get serialized automatically.

share|improve this answer
Thanks Denis. Here's an excellent tutorial on this method in case anyone else has this question > striderweb.com/nerdaphernalia/2008/07/… – Scott B Jan 6 '11 at 16:36
Wow - Had no idea. I kept trying to serialize them myself. – Don Gilbert Jan 6 '11 at 19:20
Is this format specific to WordPress? – trusktr May 28 '12 at 20:13
Note: You can also pass an object (stdClass for example). When you use get_option you will get the exact object back :) – Brian Mar 19 '15 at 19:32
@Brian: Actually, it's not stdClass for example. It's only stdClass, else WP will crash on load if the class doesn't exist, the option is set to autoload, and no class autoloader can find the appropriate class. – Denis de Bernardy Mar 19 '15 at 20:09

The serialization is done automatically, but if you want to know how to do this manually the function to look at is called serialize()

share|improve this answer

As per other answers (un)serialization is performed automatically on more complex data formats (arrays, objects) when options are stored or retrieved. This also applies to transients and other functionality.

Technically this is performed by internal usage maybe_serialize() and maybe_unserialize() functions that try to determine if data needs to be processed or passed as is.

share|improve this answer

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.