[wp-hackers] Applying a filter to the main loop only

John Blackbourn johnbillion+wp at gmail.com
Mon Jul 26 19:49:37 UTC 2010

On Mon, Jul 26, 2010 at 8:42 PM, Otto <otto at ottodestruct.com> wrote:
> Hang on, I'm confused...
> You guys keep mentioning the main "loop", but then go on to talk about
> modifying the query for it and such. But the main post SELECT query is
> run and done before the template is ever called, certainly before you
> ever get to any "loop". It helps determine what template is called, in
> fact.

That's true but I wanted a filter on the get_posts parameters, not on
the SQL query itself.

My original question was regarding pre_get_posts, which is called as
and when each loop is performed - hence why it's not possible to
determine whether you're on the main loop or an additional loop. Using
the request or parse_request filters as suggested by Andrew Nacin gets
around this issue.

> So maybe I'm misunderstanding what you're talking about here, but the
> first query is always the main one, unless it's modified by a plugin.
> The Loop just displays posts from that already-run query.
> -Otto

More information about the wp-hackers mailing list