It looks like an e-commerce plugin’s core query will be of no use to me in one particular template so I would like to discard it completely in favor of my own WP_Query loops in the template. It’s not the main query, but a secondary loop query_posts() call that I’m trying to discard downstream.
wp remove query has some good no-op pure SQL suggestions, but what would be a recommended way to stick one of those into that specific $query in pre_get_posts?
There’s not really a way to “stop” the main query. There are plenty of filters to modify it, just nothing to turn it off completely. The best you may be able to do is hook into
posts_request
, which fires right before the data is hit, and return an empty string or something non-sensical. This is still going to hit the database.Example (untested):
Instead of creating your own
WP_Query
looks in the template, why not just completely reset the query withpre_get_posts
?Then use the “main” loop for at least one of your WP_Query loops. No database hits happen until much later, so the only “wasted” overhead is WP filling query vars.
WP_Query
has a method calledinit
that basically resets everything. Call it, then set whatever query variables you need. Then you’ll need to callparse_query
again to set up the various conditionals.