Is it possible in WordPress to get ID of current post in send_headers hook? global $post and $wp_query doesn’t work or i did something wrong.
class myClass {
public function __construct() {
add_action('send_headers', array($this, 'myFunction'));
}
public function myFunction() {
// need to get post ID here
}
It looks like WordPress hasn’t gotten to the point of initiating
$wp_query
when the actionsend_headers
is triggered.As the question asks how to get the post ID this answer assumes that you have the slug in the url instead. If the slug is the last part of the url then this will get the post ID for you.
This result will need to be tested per use, but should work for most purposes.
You even can try something like this: