$post->ID and the_id() always return the wrong value

It sounds like you are altering the global $post data somewhere (usually another loop). Be sure to call wp_reset_postdata() after you are finished with something that sets up post data in an alternate loop.

Leave a Comment