[wp-hackers] What runs first? `pre_get_posts` or `posts_where`?

Leo germani leogermani at gmail.com
Fri Aug 31 12:51:52 UTC 2012


Hi Ricardo,

pre_get_posts runs first. But actually they are very different hooks.

With pre_get_posts you will manipulate the wp_query object, changing its
properties before the SQL statement is written.

posts_where is to filter the WHERE statement after all the properties of
the wp_query object were interpreted and the SQL statement is ready to run.

So the first one is easier to use and you have less chances of breaking
everything. The second one you will manipulate a string, maybe with some
regexp, its trickier...

I think you should allways try pre_get_posts first and, unless theres no
way to achieve what you like (rare cases), use posts_where and all the
other filters (posts_join, etc...)

cheers

Leo,,

On Fri, Aug 31, 2012 at 9:38 AM, Ricardo Moraleida <moraleida at gmail.com>wrote:

> Self-explaining title, I think.
>
> I'm planning on doing some heavy query-altering as soon as possible on page
> load, so I'm gathering my options, here.
>
> Also, are there any other actions like `post_where` to get other parts of
> the actual query being run against the database?
>
> Any heads-up will help.
>
> thanks!
>
> Ricardo Moraleida
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>



-- 
leogermani.com.br


More information about the wp-hackers mailing list