views:

31

answers:

1

Hello,

I'm working on a custom wordpress theme with a little bit of backend admin system.

Why I need to declare


global $options;
foreach ($options as $value) {
if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); }
}

multiple times in header and footer? Because my index.php file includes header.php and footer.php. Why can't I declare one time at the header.

thanks :)

A: 

I'm guessing it has to do with your usage of $options and variable scope. While you'll probably need global $options wherever you want to use that variable, you probably only need the foreach loop there only the first time.

Also, get_settings() is deprecated, use get_options() instead.

jay.lee
`get_option()`, not `get_options()` - and its no biggie calling this multiple times in a page load since the result is cached the first time and then pulled from cache the subsequent times. There's no extra database hits calling `get_option` as many times as you want.
Gipetto