## template include – Why does get_post() return the latest post inside template_include before doing anything

Question

Assume all the code below is in a theme’s function.php

If I add get_post() at the top, It’d get null, which is totally expected since I’m not in the loop, or nothing has been done.

add_filter('template_include', 'call_get_post'));

function call_get_posT(){
var_dump(get_post())
}


Then I’ll get the info for the latest post.

I tried this in a fresh install of WP locally so I’d assume this is expected behavior, but I don’t understand it. I’m not in the loop, and I haven’t called anything to start a query, why would get_post() return the first post? Same result if I use global \$post.

Can someone explain what’s going on here?

0
2 months 2022-08-11T11:52:58-05:00 0 Answers 0 views 0