[wp-hackers] Sidebar/Widget conditionnal tag?

Mike Schinkel mikeschinkel at newclarity.net
Tue Jan 4 21:47:38 UTC 2011


On Jan 4, 2011, at 4:33 PM, Olivier wrote:
> 
> The issue is that I have no way to differentiate between the main
> content loop and the sidebar widget loop because there is no flag
> specific to each. So when my filter applies, it applies to both and
> therefore is not efficient because I should have different filters for
> both to make this work.

Common problem, easy and much more robust solution (assuming you are calling WP_Query or get_posts() in your widget.) Subclass WP_Query and use instance variables to control state and/or add the filters before you call the instance method get_posts() and remove the filters immediately after. 

This answer can show you how:

http://wordpress.stackexchange.com/questions/6162/#6171

Hope this helps.

-Mike



More information about the wp-hackers mailing list