Ready to get started?Download WordPress


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

  1. artcoder
    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
    Posted 3 years ago #

    Try this

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

    Adding global worked. Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.