Someone explained me that using get_option is not productive, it's better to implement a custom function and then save the options in a single multidimensional array.

Before I thought that having an array like this one and using get_option('the_option_id', 'default_value') every time was a good way:

$options = array(    
array("name" => "General Settings",
    "type" => "title"),
array("type" => "open"),
array("name" => "Option 1",
   "desc" => "Description.",
   "id" => "option_id_1",
   "type" => "text"),
array("name" => "Option 2",
   "desc" => "Description.",
   "id" => "option_id_2",
   "type" => "text"),
array("type" => "close"),

He said that it's better to call the function get_option() only one time and get everything in a custom function. Why is that, when on codex they recommend to use the simple get_option($variable, $default)?

That's a theoretical question, but feel free to post or share your codes. How do you do work about that? (Most of the option frameworks use a custom function, also).


There are couple main considerations with options performance.

How many options there are

Every option with unique key is a row in options database. More rows makes table messier, but primarily for humans to work with. You'll need to have crazy amounts of options to start making serious difference in performance.

Are they autoloaded

Options are by default autoloaded. On each pageload WordPress queries all autoloaded options in bulk and puts them into cache. If you have a lot of options, which are not autoloaded then accessing them will require as many database queries. If your data in autoloaded options in considerably large then it will slow down autoload and consume as much memory.

In any case you are just using get_option(). The different is how you organize your data and how you access it. Storing array of data as single option is generally considered more neat. Any abstraction on top of that usually just simplifies getting specific pieces of data from underlying large array.

  • I see, thank you. So it's more about the organization. My theme has 90 options, approximately, but the array includes 30 more (10 sections with heading, open, close), so we are talking about 120 arrays inside the main array. I think it's not a lot. Your answer is really helpful, thanks. – Gerard Apr 21 '14 at 11:32

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.