WordPress global $post variable is empty

不羁的心 提交于 2019-12-20 04:12:25

问题


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.


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



来源:https://stackoverflow.com/questions/22745077/wordpress-global-post-variable-is-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!