php 不断给出以下内容
Warning: Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/europeiska/wp-content/themes/europeiska/get-theme-options.php on line 4
这是 WordPress 检索此信息的正确代码,为什么 PHP 会吐出此信息?
<?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']; }
else {
$$value['id'] = get_option( $value['id'] );
}
}
?>
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']; }
else {
$value['id'] = get_option( $value['id'] );
}
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可能
$options
没有在任何地方定义。Probably
$options
is not defined anywhere.问题是 $options 将是一个空值,即它已经设置了任何类型的任何数据。
The problem is that $options will be a null value i.e. it has got any data of any sort set to it.
我不确定你为什么要这样做。如果您尝试查看所有选项,请尝试此页面:http://domain.com/wp -admin/options.php 在您的 WordPress 安装上或在数据库中查找。
如果是访问特定选项的问题,为什么不直接使用 get_option() 呢?
我不认为“$options”是wordpress中自然定义的变量,因此您需要确保在运行foreach之前自己定义它。
如果您不确定 $options 是否始终被定义,则避免该错误的一种方法是在其之前添加快速检查:
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: