开发者

How to get id of post inside of plugin

I want to retrive post id inside plugin. I tried

global $post;
 $a_Id=$post->ID; 

and

global $wp_query;
$thePostID = $wp_query->post->ID;

and

var_dump(get_the_ID()); //shows just null

How i can retrieve it?

The idea is to get language of post from Custom Fields and feed it into Global Translat开发者_运维百科or plugin as a BASE LANG

EDIT: I can retrive id from $_GET['p'] on development server but on production i have pretty urls so i dont have it.


Assuming that you know what the ID is for an particular post you could use

var_dump(get_defined_vars());

to show a listing of anything that you can get your hands on. Look through the output for the ID that you know and then use the path that it shows to get there.


What are you doing with the post ID? When exactly do you need it? I'm guessing you are using this very early in your plugin file, when the query is not yet parsed. The query is parsed after the hook parse_query is fired.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜