WP_Query vs query_posts() vs get_posts()

This is not a new resource, but I just rediscovered and found it still incredibly relevant. Back in 2011, Andrey “Rarst” Savchenko put together a little diagram that shows the difference between three of the most common ways of dealing with getting posts in WordPress, a new WP_Query object, or the query_posts() or get_posts() functions.

I found my way to this chart and answer via a more recent post from Rarst. Which nearly summarizes down to:

Never use query_posts() or otherwise override the main query in a template.

And really, get_posts is nearly just a convenience wrapper around WP_Query. Want to learn more about WP_Query? Check this out:

Getting to Know WP_Query

Hope that’s helpful!


Add a Comment

Your email address will not be published. Required fields are marked *