When and Where is `global $post` Set and Available?

Global $post var is set by WP::register_globals() method.

It is called by WP::main() method, on its turn called by wp() function that is called when wp-blog-header.php is loaded.

If you look at the graph @Rarst built, on the left, you can see where wp() function is called.

In terms of hooks, global post variable is set just before "wp" hook runs, so that is first hook to be safely used to check it.

Leave a Comment