WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to use get_the_ID() in sidebar? (3 posts)

  1. artcoder
    Member
    Posted 3 years ago #

    I want to use get_the_ID() to get the custom fields for the page currently being viewed by the user. The problem is that get_the_ID() is not working in the sidebar.php. It only works inside the loop.

    I'm writing some PHP code in my sidebar.php that requires me to know the id of the current post.

    How am I to get?

  2. Reuben Gunday
    Member
    Posted 3 years ago #

    Try this

    <?php
    global $post;
    $the_post_ID = $post->ID;
    ?>
  3. artcoder
    Member
    Posted 3 years ago #

    Adding global worked. Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.