WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a page that displays information from a query (I placed the output of the query in a custom page template and have the information display that way). How can I put this information into a sidebar widget? Do I need to pull it from the page, or is there a widget that allows you to put a dynamic query inside?


share|improve this question

If you hard-coded your custom query directly in the page template, then you're going to need to duplicate that custom query in a custom Widget.

On the other hand, if you've abstracted the custom query (either into a template-part file, or better yet, a custom function), then you can simply include the template-part file or custom function in your custom Widget.

share|improve this answer

I'd solve this using the Text Widget.

Enabling shortcodes for it:

add_filter('widget_text', 'do_shortcode', 11);

And then, as Chip Bennett points out, using a custom shortcode function that will output your custom query.

share|improve this answer
IMHO, this is far more complex (and potentially dangerous) than simply creating a custom Widget... – Chip Bennett May 25 '12 at 14:21
@ChipBennett - I see... so a better answer depends on the OP showing us his Query, no? – brasofilo May 25 '12 at 14:31
absolutely :) – Chip Bennett May 25 '12 at 14:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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