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

Luke Lee
7,577 PointsWhy do we have if(have_posts()) and while ($the_query->have_posts()) ?
Both if and while are conditional statement. why do we have both of them here?
<?php if(have_posts()): while ($the_query->have_posts()): $the_query -> the_post(); ?>
if(have_posts()) means if there are posts while ($the_query->have_posts()) means while there are posts in the query, do something
Can't we just use
<?php if($the_query->have_posts()): $the_query -> the_post(); ?>
1 Answer
Rick Silva
Courses Plus Student 99 PointsTry it.
Luke Lee
7,577 PointsLuke Lee
7,577 PointsYeah, I tried it. it only displayed one post. OK, I see, while is a loop.