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

Problems with WP_Query

So I'm following the tutorial over here at,

http://teamtreehouse.com/library/wordpress-custom-loops-with-wpquery

I seem to be running into an issue with my code where rather than displaying the set category "music" it simply displays the page content again.

I am using the 2015 theme instead of the 2012 theme used in the video. Can anyone help point me in the right direction why my code is displaying the page content twice rather than displaying the page content followed by the posts in category "music"?

My code is here, http://pastebin.com/thh2UxbA

2 Answers

Mate Maksan
Mate Maksan
2,395 Points

That is because you call standard loop two times. You should have on line37 in your example this line to call query loop:

 ```<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>```

I managed the solved the problem. For anyone who has this issue in the future. You an not simply copy and paste the loop to start a new loop. After the reset you need to specify the use of the $the_query in the 2nd loop.