Best way to retrieve theme options
-
Hello, I’m recently finishing a wordpress theme and I have a couple of questions regarding the best way to retrieve the themes options.
Almost all tutorials I’ve read mention that the following code snippet should be used in every page I need such options:
global $options; foreach ($options as $value) { if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); } }
That works just perfectly, however sometimes I just need 1 or 2 variables from the themes options and loading all of them just – for that one variable – seems excessive, so I use:
get_option('variable_example')
And that also works, however it seems to me that the first method only require on access to the DB and the second method requires one access per get_option call, however I’m not loading all the options into memory. My question is the following:
Witch is better? Loading all of them, accessing them one y one or using both methods depending on the situation? If so, how many times is using get_option too many times? ??
- The topic ‘Best way to retrieve theme options’ is closed to new replies.