[wp-hackers] identifying the current wp_query() instance
malaiac at gmail.com
Sun Sep 14 10:10:12 GMT 2008
I am playing with the 'posts_where' filter, called by WP_Query::get_posts()
the call is : $where = apply_filters('posts_where', $where);
My function is add_filter('posts_where','my_filter_function');
In a page, let's say I have :
one regular $wp_query, showing the posts of the homepage
one $last_pages = another WP_Query
one $most_commented_posts = another WP_Query
These three queries will run through the posts_where filter.
How may the my_filter_function know which one it is ?
How could the my_filter_function know if it's a page or post, or stg
other, query ?
What if my_filter_function needs to know the current query vars ?
global $wp_query; print_r($wp_query->query_vars); will work only for
the first one (and wrong for the two others)
global $qv / global $q; won't work since $qv and $q are not declared global;
I could manually test in the function (if($most_commented_posts)
then() elseif $last_pages then() else (...use $wp_query) )... not very
any other ideas ? I'm not an OOP guru, so I may miss something here.
More information about the wp-hackers