I have a widget for displaying my site's categories on the frontpage. The widget admin form has a checkbox list of categories for controlling the widget output. What's the best way to retrieve the saved values from the category selection? The data is saved as $instance['widget_categories']. So, I want to retrieve the category id's and then use them in the include parameter of the get_categories() array.

2 Answers 2

$wg_class = new Widget_Toggle_Title();
$settings = $wg_class->get_settings();


Replace Widget_Toggle_Title class with yours.

  • I think you might have misunderstood the question.
    – jrcollins
    Sep 17, 2016 at 4:39

The answer to this question is very simple:

$catsin = $instance['widget_categories'];
$child_categories = get_categories( array(
  'orderby' => 'id',
  'hide_empty' => 0,
  'include' => $catsin
) );

This is what I originally tried to do but I made the basic error of enclosing the variable in quotes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.