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 How to Build a WordPress Theme WordPress Theme Functions Displaying Custom Posts and Fields in a Template

Joachim Hagege
Joachim Hagege
16,297 Points

calling to have_posts() with WP_Query($args)

Hello guys, I don't understand why in the following code: <?php if ( have_posts() ) : while ($the_query->have_posts() ) : $the_query->the_post();?>

We call first if (have_posts()) and not if ($the_query->have_posts()) Is it a typo or is it on purpose? Shouldn't it be more logical to check if "the_query" has posts and not "any posts" WP blog would maybe contain?

I hope I've been clear enough. Best

1 Answer

Kevin Korte
Kevin Korte
28,149 Points

I'm not sure, but the WP Codex shows checking the if statement with the query variable as well. I'd probably do it that way if everything still worked fine.