Does WordPress run a post query when a page is invoked?

Yes, it does. Pages are just a type of post.

If you visit, say, https://test.test/sample-page/, then this happens:

  1. WordPress checks the URL against its stored rewrite rules.
  2. On a normal site, https://test.test/sample-page/ will match (.?.+?)(?:/([0-9]+))?/?$, which the rule maps to index.php?pagename=$matches[1]&page=$matches[2].
  3. WordPress performs a query using WP_Query, with the pagename argument set to pagename. Our URL doesn’t include a page number, so it will be whatever the default is.
  4. WordPress recognises this as a query for a single Page, and sets the appropriate values for the is_page, is_singular etc. properties of the query. is_main_query will also be true for the query based on the URL parameters.
  5. Recognising that this is a query for a page, WordPress loads the appropriate template from the theme using the Template Hierarchy.

There’s a lot more that goes on, but this is the basic overview. A huge number of action and filter hooks are fired during this process, so I can’t list them all here, but WP_Query related hooks like pre_get_posts do run when viewing pages.

tech