views:

274

answers:

0

I want to get the widget ID of the first widget that belongs to a specific widget class on a Wordpress page.

That is, if there are three text widgets available on the page with widget ids widget_text-14, widget_text-2 and widget_text-8 (appearing in this order), I would like to get "14".

I tried making use of is_active_widget as part of the solution, but as it turns out, this checks if a widget is active globally, not on that specific page. Further, if I print the array of widgets of that type, it lists inactive widgets as well (ie. widgets that are not included in that sidebar but lying among the inactive widgets on widget admin page.)

My eventual goal is to be able to use something like:

$toggleImage = $text_widgets[14]['toggle'];

ang get the url to the specified image.

It would be ideal to arrive to a WP solution, but I'm thinking that a javascript or jQuery solution may work as well. I opened another question for that here