Best way to retrieve theme options (2 posts)

  1. alexmoba
    Posted 6 years ago #

    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:


    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? :P

  2. Jauhari
    Posted 6 years ago #

    Why get_option('variable_example') doesn't work before we tried to save our theme options configurations?

Topic Closed

This topic has been closed to new replies.

About this Topic