开发者

php keeps giving the following

Warning: Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/europeiska/wp-content/themes/europeiska/get-theme-options.php on line 4

This is the correct code for Wordpress to retrieve this info, why is PHP spitting this out?

<?php
//allows the theme to get info from the theme options page
global $options;
foreach ($options as $value) {
    if (get_option( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; }
    els开发者_StackOverflow社区e { 
        $$value['id'] = get_option( $value['id'] ); 
    }    
}

?>


Probably $options is not defined anywhere.


The problem is that $options will be a null value i.e. it has got any data of any sort set to it.


I am not sure why you are trying to do this. If you are trying to view all the options, try this page: http://domain.com/wp-admin/options.php on your wordpress install or look in the database.

If it is a matter of accessing a specific option, why not just stick with get_option() ?

I don't think that "$options" is a naturally defined variable in wordpress, so you need to be sure to define it yourself before running the foreach.

A way to avoid that error, if you are not sure if $options will always be defined is to add a quick check right before it:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜