WordPress global $post variable is empty

I’m working on a wordpress plugin(managing background image), when I try to use

global $post;
print_r($post);

the object is empty.
Probably there is some required data (I dont know what.)
Please help me if you know.

Related posts

Leave a Reply

1 comment

  1. The WordPress global variable $post contains the data of the current Post within the The Loop.

    This means that WordPress will assign a value to this variable in each loop iteration. Consecuently, if you’re trying to access $post from anywhere in your code outside the WP loop, it will be of course empty…