[wp-hackers] new WP_Query vs. get_posts() - any difference?
jayarjo at gmail.com
Wed Dec 23 20:34:27 UTC 2009
Is there any benefit of running get_posts(), for example can it be
more efficient, since it doesn't retrieve all that additional info? Or
it is the same, since as Austin said it instantiates WP_Query?
On Thu, Dec 24, 2009 at 12:20 AM, Jeremy Clarke <jer at simianuprising.com> wrote:
> 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
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
More information about the wp-hackers