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

Luke Lee
Luke Lee
7,577 Points

Why 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

Try it.

Luke Lee
Luke Lee
7,577 Points

Yeah, I tried it. it only displayed one post. OK, I see, while is a loop.