Consider a doing_it_wrong call for query_posts()
|Reported by:||johnbillion||Owned by:|
The query_posts() function affects the main query, so things (like template conditionals) can break if plugins or themes use it without calling wp_reset_query() immediately afterwards.
Unless there is a situation I haven't considered, query_posts() shouldn't be used at all on requests where the main query is run (query_posts() of course has a use in situations like AJAX calls when the main query isn't run).
- For secondary loops, get_posts() or the WP_Query() class should be used.
- To modify the main query, there are hooks all over the place, such as 'request', 'parse_request', 'parse_query', and 'pre_get_posts', in addition to the SQL filters such as 'posts_where', 'posts_join', etc.
Maybe doing_it_wrong() should be called if query_posts() is used after the main query is run, with pointers toward a relevant Codex article on secondary loops or filtering the main loop.
Change History (13)
3 years ago
- Keywords close added
- Milestone Awaiting Review deleted
- Milestone set to Future Release
- Resolution wontfix deleted
- Status changed from closed to reopened
in reply to:
21 months ago
- Keywords has-patch needs-docs added; close removed