Muaaz Khalid
Muaaz Khalid

Reputation: 2249

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.

Upvotes: 1

Views: 4958

Answers (1)

MikO
MikO

Reputation: 18741

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...

Upvotes: 7

Related Questions