Replaced queried object id with already available global post.
Check if the page is a single page / post / attachment and uses post object instead of post id.