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
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.
get_posts is nearly just a convenience wrapper around
WP_Query. Want to learn more about WP_Query? Check this out:
Hope that’s helpful!