How to access $post from a callback function

Short answer “no”, using globals is never a best practice, indicates that you might be trying to do something in the wrong place, and should be left as a last resort.

In your snippet for example you have no idea who set the $post, was it set in the loop or outside it, was it a single post loop, etc.

As a rule of thumb never use globals, they are just evil.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)