[wp-hackers] new WP_Query vs. get_posts() - any difference?
Davit Barbakadze
jayarjo at gmail.com
Wed Dec 23 18:06:51 UTC 2009
So if I just add suppress_filters=0 into get_posts() it will make
those two approaches identical?
Thank you for explanation!
On Wed, Dec 23, 2009 at 8:27 PM, Austin Matzko <austin at ilfilosofo.com> wrote:
>
> On Wed, Dec 23, 2009 at 10:10 AM, Davit Barbakadze <jayarjo at gmail.com> wrote:
> > When I need custom loop with wp tag support I usually do:
> >
> > <?php if ($posts = get_posts("cat=4,7")): ?>
>
> [snip]
>
> > But sometimes I see a different approach:
> >
> > <?php $query = new WP_Query("cat=4,7");
>
> [snip]
>
> > and codex uses it to for demonstration of how the custom loop should be
> > called. First approach is obviously cleaner, but maybe it has unobvious
> > drawbacks?
>
> Most of the time those two approaches will have the same result.
> However, you should keep in mind that get_posts() by default sets its
> "suppress_filters" argument to true, so if a plugin tries to customize
> results via the WP_Query filters, it will be able to change the
> results in your second, WP_Query example but not the first,
> get_posts() example. Since most themes use WP_Query or query_posts,
> most plugin authors have a reasonable expectation that they'll be able
> to use the WP_Query filters to affect theme output, and any themes you
> make with default get_posts() will defy those expectations.
>
> Also, since get_posts() instantiates WP_Query() itself, the second
> route is more direct.
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
--
Davit Barbakadze
More information about the wp-hackers
mailing list