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 |1 Answer
Reset to default 1Yes, it does. Pages are just a type of post.
If you visit, say, https://test.test/sample-page/
, then this happens:
- WordPress checks the URL against its stored rewrite rules.
- On a normal site,
https://test.test/sample-page/
will match(.?.+?)(?:/([0-9]+))?/?$
, which the rule maps toindex.php?pagename=$matches[1]&page=$matches[2]
. - WordPress performs a query using
WP_Query
, with thepagename
argument set topagename
. Our URL doesn't include a page number, so it will be whatever the default is. - 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. - 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
版权声明:本文标题:Does Wordpress run a post query when a page is invoked? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741498617a2381950.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
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