I read @nacin's You don't know Query yesterday and was sent down a bit of a querying rabbit hole. Before yesterday, I was (wrongly) using
query_posts() for all my querying needs. Now I'm a little bit wiser about using
WP_Query(), but still have some gray areas.
What I think I know for sure:
If I'm making additional loops anywhere on a page—in the sidebar, in a footer, any kind of "related posts", etc—I want to be using
WP_Query(). I can use that repeatedly on a single page without any harm. (right?).
What I don't know for sure
- When do I use @nacin's
WP_Query()? Should I use
pre_get_postsfor everything now?
- When I want to modify the loop in a template page — lets say I want to modify a taxonomy archive page — do I remove the
if have_posts : while have_posts : the_postpart and write my own
WP_Query()? Or do I modify the output using
pre_get_postsin my functions.php file?
The tl;dr rules I'd like to draw from this are:
- Never use
- When running multiple queries on a single page, use
- When modifying a loop, do this __________________.
Thanks for any wisdom
ps: I have seen and read: When should you use WP_Query vs query_posts() vs get_posts()? Which adds another dimension —
get_posts. But doesn't deal with
pre_get_posts at all.