I have a widget with 6 different options. When I use get_option, it gives me a multidimensional array, with all my options inside the inner array, like so:
$options = get_option('widget_widgetname');
var_dump($options);
And the output for var_dump is:
array(2) { [2]=> array(5)
{
["string"]=> string(6) "Search"
["title"]=> string(12) "WDSearchForm"
["show_wrapper"]=> string(0) ""
["animate"]=> string(0) ""
["animateWidth"]=> string(2) "80"
}
["_multiwidget"]=> int(1) }
Therefore, in order to use the options, I would have to do $options[2]["optionName"] rather than the desired $options["optionName"].
Why does Wordpress does that? Is it always going to be under "2"? Is there a better way to retrieve those options?
$instance(which also indirectly answers your question as to why it's a multi-dimensional array). – Milo Jan 14 at 19:51widgetfunction, your options are$instance['title'],$instance['animate'], etc.. – Milo Jan 14 at 20:06