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

I have a site where I display the same exact footer on every page. There is one exception, though. On one certain page I need to change one small part of the footer.

I figure the simplest way to do this is to check, within the footer, whether I’m on that page or not. It wouldn’t make sense to change the whole entire footer for that page since I’m only changing a tiny part of the footer, deep within the footer.

The problem is that whenever I call $post->ID or the_id() from within the footer, it gives me an ID that clearly doesn’t match the post I’m on. It always gives me 89, no matter what page I’m on in the site.

I figure I must be doing something wrong. Can anyone tell me what it is?

5 s
5

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