WordPress.org

Ready to get started?Download WordPress

Forums

Best way to retrieve theme options (2 posts)

  1. alexmoba
    Member
    Posted 4 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:

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

  2. Jauhari
    Member
    Posted 4 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