WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have read a number of questions on SE regarding these but I still can't figure the exact difference wrt usage. Would it be true to say that I would probably use WP_Query for the majority of secondary loops and only use get_posts if I need the results returned in an array, or to put it another way is the main difference between the two the array vs object return, or is there some other major factor I should be aware of?

share|improve this question
up vote 11 down vote accepted

The difference between get_posts & WP_Query

You can view get_posts() as a slimmed down WP_Query. In fact looking at the source:

//... prepares query array $r
$get_posts = new WP_Query;
return $get_posts->query($r);

get_posts() use WP_Query, but only returns an array of posts - nothing more. Furthermore it sets:

$r['no_found_rows'] = true;

Normally (by default with WP_Query object) - WordPress queries how many posts there are in total - even if you are only after the first 10. It does this so it can perform pagination. So get_posts() is actually (slightly) quicker (it also ignores sticky posts).

Which to use...

If you only need an array of posts, and don't need the query object -use get_posts(). Otherwise, if you do need the access to the query object methods, or pagination, or sticky posts at the top, you should use WP_Query.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.