Get Widget Instance inside Widget

You can get widget options using following code

$current_widget_options = $this->get_settings();

This will return array like array(instance number => settings). Instance number refers to the $number of widget.

Example: If your widget instance number is 2 then your required options will be at $current_widget_options[2]

Alternative:

As get_settings() is deprecated, you can use get_option. Check following example:

  $widget_options_all = get_option($this->option_name);
  $options = $widget_options_all[ $this->number ];

Leave a Comment