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 trialIlya Liverts
9,677 PointsHow to create custom loops?
To create custom loops in our WordPress templates, we use the____ function. I have no idea what to fill here. That question from quiz.
2 Answers
John Leskas
24,093 PointsWP_Query function is the answer:
An example of this function would be:
<?php $args = array( 'post_type' => 'post', 'tax_query' => array( array( 'taxonomy' => 'people', 'field' => 'slug', 'terms' => 'bob', ), ), ); $query = new WP_Query( $args );
// The Loop if ( $the_query->have_posts() ) { echo '<ul>'; while ( $the_query->have_posts() ) { $the_query->the_post(); echo '<li>' . get_the_title() . '</li>'; } echo '</ul>'; } else { // no posts found } /* Restore original Post Data */ wp_reset_postdata();
Ryan Cates
18,344 PointsIn addition to John's comment... this might be a bit much if you're a beginner to WordPress but this will help to understand what you can do with loops. Codex