admin管理员组文章数量:1122832
On a category archive page, in a filter called from a block outside a loop, I noticed that the get_post
function with a null
first parameter returns the first loop's post.
Is it supposed to return such a value ? I would have imagined that the global $post
variable should have a value only in a loop or on a post page.
On a category archive page, in a filter called from a block outside a loop, I noticed that the get_post
function with a null
first parameter returns the first loop's post.
Is it supposed to return such a value ? I would have imagined that the global $post
variable should have a value only in a loop or on a post page.
- Can you add your code snippet here please – Pratik bhatt Commented Apr 15, 2024 at 11:51
1 Answer
Reset to default 1Yes, this is how it is supposed to work. The global $post
variable is set quite early in the page load, at the wp
hook. As you can see from the hook order, this is before the loop starts.
Basically the $post
object exists independent from its actual content in the database, which you retrieve during the loop. It's specifically meant to be accessible all the time during page generation.
本文标签: Global post value outside the loop
版权声明:本文标题:Global $post value outside the loop 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736310456a1934382.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论