Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

2 Answers

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.

EDIT

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
add comment

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
add comment

Your Answer

 
discard

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.