WordPress.org

Ready to get started?Download WordPress

Forums

Current page id outside the loop (4 posts)

  1. levani01
    Member
    Posted 5 years ago #

    How can I write current page ID outside the loop?

  2. ittekudasai
    Member
    Posted 5 years ago #

    Should be just $post->ID but if you get it working let me know... when I do this it keeps returning a number that is incorrect.

  3. Creative Slice
    Member
    Posted 5 years ago #

    while $post->ID should work it's a better idea to use

    $wp_query->post->ID

    especially if you are going to be doing this outside of the loop.

  4. Ryan S
    Member
    Posted 5 years ago #

    I have once used $wp_query->post->ID, and it worked fine. But I am still not sure about it..

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.