Exercise 1: Why the Footer Shows the Wrong Title After a Forgotten wp_reset_postdata() — Possible Solution ==================================================================== WHAT the_post() ACTUALLY SETS UP, PER THIS CHAPTER ------------------------------ Per this chapter, the_post() "sets up the global post data every template tag... reads from, so each iteration's template tags correctly refer to that iteration's own post." Every time the_post() runs - inside the main Loop OR inside a custom WP_Query's own loop - it overwrites this same shared global post data to point at whichever post is currently being iterated. WHAT HAPPENS WHEN THE RELATED-POSTS QUERY RUNS ------------------------------ The Related Posts section's own WP_Query loop calls $related->the_post() repeatedly as it iterates through its five related posts. Each call overwrites the SAME global post data the main query's own the_post() had originally set up for the actual single post being viewed. By the time that related-posts loop finishes, the global post data is left pointing at whichever related post was iterated last - not the original single post the page is actually about. WHY wp_reset_postdata() EXISTS, AND WHY SKIPPING IT MATTERS ------------------------------ Per this chapter's own warn-box, "after the custom loop finishes, that global state still points at the LAST POST IN THE CUSTOM QUERY, not back to the original post the main query was on... Any template tags used after the custom loop, but before calling wp_reset_postdata(), will silently reference the wrong post's data." wp_reset_postdata() is specifically the function that restores the global post data back to the original, main-query post - skipping it leaves that corrupted state in place for anything that runs afterward. WHY THE FOOTER SPECIFICALLY SHOWS THE WRONG TITLE ------------------------------ Since the Related Posts section runs "near the bottom of a single-post template" and wp_reset_postdata() was never called after it, the footer's own the_title() call executes while the global post data is still left pointing at the last related post from that custom query - not the actual single post the visitor is viewing. the_title() simply reads whatever the global post data currently says, with no way to know that data was supposed to have been restored first. WHY THIS WORKS AS AN ANSWER ------------------------------ It explains precisely what global state the_post() modifies, traces exactly how the related-posts loop leaves that state pointing at the wrong post, and connects that corrupted state directly to why the footer's own the_title() call then displays the wrong title - using this chapter's own explicit wp_reset_postdata() warning throughout.