[wp-hackers] Sidebar/Widget conditionnal tag?

Cornelius, Gregory gcorne at bu.edu
Tue Jan 4 17:04:54 UTC 2011

You could add the filter using the action "get_sidebar" and remove it immediately.

function foo_get_sidebar_action() {
	add_filter('posts_where', 'foo_filter_posts');

function foo_filter_posts($where) {
	remove_filter('get_sidebar', 'foo_get_sidebar_action');

	// manipulate $where	
	return $where;

The context (usually a sidebar) that is generating the widget  is not passed to the widget code, and unfortunately, there isn't an action that runs somewhere in the "display_callback" method.

On Jan 4, 2011, at 9:11 AM, Olivier wrote:

> Hello,
> I need to filter widget content (for recent posts and recent
> comments). The issue I am facing is that the posts_where filter I am
> hooking on is applicable to the entire page queries (ie main content +
> sidebar).
> Please, is there a way to check if the query is performed from the
> sidebar or widget?
> Something like is_sidebar or is_widget would be nice to perform some
> tests in the filter hooks.
> Thanks!
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

More information about the wp-hackers mailing list