5

What are the differences between using WP_Query() and get_posts()? Which is better to use in what case and why?

2

2 Answers 2

6

Well, get_posts() actually instantiates a new WP_Query object, so if you're comfortable using WP_Query directly, don't even bother with get_posts(); get_posts will only return the results from the database, whereas WP_Query gives you the whole functionality of the class.

1

In addition to what John P Bloch says, you can modify the default WP_Query object (instead of creating an new instance) before it runs with it's class methods and an action hook, reducing the db calls you make.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.