Support » Themes and Templates » Weird the_ID error

Viewing 4 replies - 1 through 4 (of 4 total)
  • This is actually expected behavior for the_ID(). It’s goal is to echo the ID of the post, and it appears to be doing that quite well. So to return or pass the post ID to the get_post_meta() function, use this instead:

    $post->ID

    You can also try $id which is a global var in WordPress and typically available within The Loop.

    Thanks for the assist. Either of those seems to work.

    The behavior of the_ID() does seem to fly in the face of logic though — if the function returns the post ID, then why would it overwrite an entire other function containing it?

    Whatever — It’s working now. Thanks a bunch!

    the_ID() does not return the value, it just echoes or prints it. With PHP there’s a difference between the two.

    I was trying to assign the_ID() to a var to use in a custom query and it was driving me nuts since echoing was working fine. I don’t really understand it but $id worked.

    However, if someone wants to explain that, more specifically, how could/would you store the results from the_ID() in a variable so you could use it as an int?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Weird the_ID error’ is closed to new replies.