Laurent Duretz
Member
Posted 4 years ago #
Hi,
I'm working on a sidebar widget and I need to get the page/post id of the page I calculate.
I can't une the_ID because the sidebar is outside The Loop.
I've read something like rewind_post() and I've to test it.
Does somebody have another way to retreive this ID ?
Thanks,
Laurent
bandwagon
Member
Posted 4 years ago #
I'm a bit surprised the answer to this question is so difficult to find. Or maybe I don't know where/how to look. I've tried the following function, but it's not working for in my widget (though it does work for me directly when I hard code it into sidebar.php).
`// Works in single post outside of the Loop
function function_name() {
global $wp_query;
$thePostID = $wp_query->post->ID;
}`