# The Main Loop & Template Loading

* The main query is a `WP_Query` object
* The main loop is using that main query
* The main query is done before the template is even loaded
* The template is loaded based on what the main query is
* The main query is determined by parameters called query variables
* Which template is loaded when is shown on the template hierarchy diagram
* All templates are just custom ways of showing the main post loop


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.wptherightway.org/routing/the_main_loop_and_template_loading.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
