[wp-hackers] new WP_Query vs. get_posts() - any difference?

Jeremy Clarke jer at simianuprising.com
Wed Dec 23 20:20:24 UTC 2009

On Wed, Dec 23, 2009 at 1:14 PM, Austin Matzko <austin at ilfilosofo.com> wrote:
> On Wed, Dec 23, 2009 at 12:06 PM, Davit Barbakadze <jayarjo at gmail.com> wrote:
>> So if I just add suppress_filters=0 into get_posts() it will make
>> those two approaches identical?

They won't be identical because the data contained in the variable
($posts or $query) is very very different. When you do get_posts() you
get an array of posts only, when you do new WP_Query() you get a much
more complicated object full of information about the query and its
results. Things like the current paged value, the number of total
available results/total potential pages. Do a print_r() of the results
of WP_Query() to see what I mean.

I prefer using new WP_Query because I like having access to that stuff
directly, and using get_posts you give up all that info. A lot of it
would be available using general functions if you ran query_posts()
which resets the main query for the whole page, but can still be
useful on your mini-loops and is missing if you do get_posts().

Jeremy Clarke | http://jeremyclarke.org
Code and Design | http://globalvoicesonline.org

More information about the wp-hackers mailing list