[wp-hackers] Filters on get_posts()
johnbillion+wp at gmail.com
Mon Oct 11 14:30:26 UTC 2010
On Mon, Oct 11, 2010 at 1:02 PM, Casey Bisson <casey.bisson at gmail.com> wrote:
> I think your approach here is good. That is, there's no reason a filter has to be blindly activated as WP is instantiated, and the globally applied.
I've never thought about it that way actually. I always thought of
subsequently removing filters at runtime as being a bit hacky, but
> Filters such as you describe should look at the context of the query and optionally activate themselves. Then immediately deactivate once their work is done. The parse-query and pre-get-posts actions are good places to apply filters, then simply remove_filter() as you run them.
> If you're running multiple loops, you can do yourself a favor by calling do_action('my_loop_name') just before calling wp_query(), as that will give you an opportunity to set whatever filters you want based on that specific loop/query.
I'll try this approach and see how I get on. Cheers.
More information about the wp-hackers