admin管理员组

文章数量:1290377

Let's say I create a what in the Wordpress backend is called a page (pages - new page). I put some arbitrary page elements on it (e.g. title, text, some images, a widget or two displaying posts from various categories). I don't assign a particular template to it, so the (whatever) theme's default template is used. I publish that page, and now somebody clicks on it.

What is the data and control flow of Wordpress now?

Does it execute a post query before/when loading the page, eventually using some filters (which)?

Let's say I create a what in the Wordpress backend is called a page (pages - new page). I put some arbitrary page elements on it (e.g. title, text, some images, a widget or two displaying posts from various categories). I don't assign a particular template to it, so the (whatever) theme's default template is used. I publish that page, and now somebody clicks on it.

What is the data and control flow of Wordpress now?

Does it execute a post query before/when loading the page, eventually using some filters (which)?

Share Improve this question asked Jun 17, 2021 at 6:27 RazzupaltuffRazzupaltuff 1396 bronze badges 1
  • Pages are posts of type page, they're stored and handled internally the same way, with the same APIs, there is no difference – Tom J Nowell Commented Jun 17, 2021 at 9:53
Add a comment  | 

1 Answer 1

Reset to default 1

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.

本文标签: Does Wordpress run a post query when a page is invoked