Querying Posts Without query_posts
Really good explanation of why you shouldn’t use query_posts; a function I know I’ve used in the past but definitely stay away from now 🙂
Here at WordPress.com, we have over 200 themes (and even more plugins) running inside the biggest WordPress installation around (that we know of anyway!) With all of that code churning around our over 2,000 servers worldwide, there’s one particular WordPress function that we actually try to shy away from; query_posts()
If you think you need to use it, there is most likely a better approach. query_posts() doesn’t do what most of us probably think it does.
We think that it:
- Resets the main query loop.
- Resets the main post global.
But it actually:
- Creates a new WP_Query object with whatever parameters you set.
- Replaces the existing main query loop with a new one (that is no longer the main query)
Confused yet? It’s okay if you are, thousands of others are, too.
This is what query_posts actually looks like:
Rarely, if ever, should anyone need to do this. The most…
View original post 749 more words