WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. Laurent Duretz
    Member
    Posted 6 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

  2. bandwagon
    Member
    Posted 6 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