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.
精彩评论