The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

[resolved] Howto get the post ID displayed (2 posts)

  1. Laurent Duretz
    Posted 8 years ago #


    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 ?


  2. bandwagon
    Posted 8 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;

Topic Closed

This topic has been closed to new replies.

About this Topic