What are the differences between using WP_Query()
and get_posts()
? Which is better to use in what case and why?
Leave a Reply
You must be logged in to post a comment.
What are the differences between using WP_Query()
and get_posts()
? Which is better to use in what case and why?
You must be logged in to post a comment.
Well,
get_posts()
actually instantiates a newWP_Query
object, so if you’re comfortable usingWP_Query
directly, don’t even bother withget_posts()
;get_posts
will only return the results from the database, whereasWP_Query
gives you the whole functionality of the class.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.