Infographic: Make Sense of WP Query Functions

As a WordPress developer you’ll most likely be familiar with a number of ways to query post data. But which WP Query Function should you use?

As explained on this thread over at WordPress Answers by Stack Exchange:

  • query_posts() might be used in one and only case if you need to modify main query of page (for which there are better and more reliable methods to accomplish, over simplistic approach of this function). It sets a lot of global variables and will lead to obscure and horrible bugs if used in any other place and for any other purpose;
  • get_posts() is very similar in mechanics and accepts same arguments, but returns array of posts, doesn’t modify global variables and is safe to use anywhere;
  • WP_Query class power both behind the scenes, but you can also create and work with own object of it. Bit more complex, less restrictions, also safe to use anywhere.

“I want to stress that query_posts() wrongfully overused in many tutorials around. It is one of the most widespread bad practices”.

– The above is great info from Rarst.net

Make Sense of WP Query Functions