how to prevent default wp query (used in "the loop") from running?
-
I use a custom query in my home template and don’t need the default wp query that wordpress generates to be used for “the loop.”
As stated at https://codex.www.ads-software.com/Function_Reference/query_posts :
“If you use query_posts within a template page, WordPress will have already executed the database query and retrieved the records by the time it gets to your template page (that’s how it knew which template page to serve up!). So when you over-ride the default query with query_posts(), you’re essentially throwing away the default query and its results and re-executing another query against the database.
This is not necessarily a problem, especially if you’re dealing with a smaller blog-based site. Developers of large sites with big databases and heavy visitor traffic may wish to consider alternatives, such as modifying the default request directly (before it’s called). The request filter can be used to achieve exactly this.”
I am not using query_posts nor modifying the default request with the “request” filter or the “pre_get_posts” filter. I just have no need for this default wp query, as I won’t even be calling “the loop” in my custom home template. I know it’s not necessary, but just to save on mysql queries, can I prevent the default wp query from running in the first place? Say, on my functions.php, something like:
if (is_home()) then don't run the default wp query...
- The topic ‘how to prevent default wp query (used in "the loop") from running?’ is closed to new replies.