ApPeL
ApPeL

Reputation: 4921

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']; }
    else { 
        $$value['id'] = get_option( $value['id'] ); 
    }    
}

?>

Upvotes: 0

Views: 151

Answers (3)

Jake
Jake

Reputation: 2086

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'] ); 
    }    
}

Upvotes: 0

James Culshaw
James Culshaw

Reputation: 1057

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

Upvotes: 1

KingCrunch
KingCrunch

Reputation: 132061

Probably $options is not defined anywhere.

Upvotes: 1

Related Questions