Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAdam Roberts
3,538 Pointswp_reset_postdata()
I'm following along with Zac in "How to Build a WordPress Theme" and I'm getting confused in the section on "Extending WordPress Template Functionality". After he talks about wp_reset_postdata(), he doesn't seem to ever use it, even when there are multiple loops in a template. I even searched through the code files he posted and couldn't find it.
After reading [http://codex.wordpress.org/Function_Reference/wp_reset_postdata] it looks like you only need it when you go back to a previous loop, like in a nested loop. Am I understanding that correctly? Zac's code works fine without it, but I want to make sure I understand when I would need it.
3 Answers
Zac Gordon
Treehouse Guest TeacherHey Adam, yeah I realized this way after recording. Technically you're right, although sometimes funky stuff comes up and it is helpful to use. Had to make a call not to go re-record this because I would then need to re-record all the code following it :-/ Sorry for the inconvenience here!
Robert Sullivan
1,549 PointsThis confused me too for a while. Helpful that the project files do include the reset_postdata. Just wanted to say how helpful I find your videos Zac! Rob.
Boon Kiat Seah
66,664 PointsThat is sure helpful , you guys are awesome!
Adam Roberts
3,538 PointsAdam Roberts
3,538 PointsHey, Zac! Thanks! Now I can go back to my regularly-scheduled programming. :)
Zac Gordon
Treehouse Guest TeacherZac Gordon
Treehouse Guest TeacherHahaha :p