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 know this is a very general question, but I have been reading tuts on both wp Query, and The Loop, and it seems that you can go either way. Am I misunderstanding this? What I think I am reading is that you can bypass the loop more or less, and just query the db. If this is the case, what is better?

share|improve this question

There is no absolute better/worse/best/worst implementation. The correct implementation depends on what you're trying to accomplish.

For a great explanation, I direct you to this post by Digging Into WordPress, which explains the 4 basic means of interacting with the WordPress Loop:

  • Default Loop

    So what makes it “default”? Mostly because it uses the default query to loop through post content, making it the loop used like 99% of the time for most themes. It tells WordPress to loop through posts and display the information according to context

  • Loop with query_posts()

    The query_posts function enables us to modify the [default] query and display our desired results. We can either override the entire query or keep it around and just change a few parameters.

  • Loop with WP_Query()

    Use WP_Query for creating multiple, customized loops. By setting up additional instances of WP_Query in your theme, you can create any number of multiple loops, and customize the output of each.

  • Loop with get_posts()

    Use the get_posts() function to easily create additional, static loops anywhere in your theme. get_posts accepts the same parameters as query_posts, and is perfect for adding static, custom loops to your sidebar, footer, or anywhere else.

Give that post a read; it will help you understand when/how to use each option.


p.s. more from Digging Into WordPress: if you use one of these methods to modify the query, you will want to familiarize yourself with when/how to reset the query.

share|improve this answer
Thank you very much Chip. This is the reading I was looking for. There is just so much information out there, and so little time. It wasn't like this in the 90's! – jerry Sep 30 '11 at 22:58

Another thought to bear in mind:

If there is ever to be the possibility that you may want to allow others to integrate with your code eg; to make mods without modifying the source, then chose a method where there are already wp filters, so that others may add filters to your code (eg to select only certain categories, or apply meta query selection etc)

Querying the database directly with your own select call for example would NOT offer these possibilities.

Sometimes it is hard to image what people may want to do, but allowing for the integration can make your plugin/theme very powerful.

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.