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 trial

WordPress

wp_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
STAFF
Zac Gordon
Treehouse Guest Teacher

Hey 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!

Hey, Zac! Thanks! Now I can go back to my regularly-scheduled programming. :)

This 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
Boon Kiat Seah
66,664 Points

That is sure helpful , you guys are awesome!