Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Looping WP Loops
Useful for minimizing code when you need to make multiple WP_Queries. Ignore the weird variable names. Used originally on a site with CPTs and taxonomies. Adapt as necessary.
//Collect taxonomies to query.
$skeelzray = array('still-life','landscape','portrait');
$skeelz = array();
//Create array of objects
foreach($skeelzray as $skeel) {
$skeelz[] = new WP_Query('posts_per_page=3&post_type=projects&skill='.$skeel);
//Loop through the array of objects
foreach($skeelz as $skeel) { ?>
<div id="<?php echo $skeel->query['skill']; ?>">
<h2><a href="<?php echo get_bloginfo('url').'/skill/'.$skeel->query['skill']; ?>"><?php echo $skeel->query['skill']; ?></a></h2>
<?php if($skeel->have_posts()) : while($skeel->have_posts()) : $skeel->the_post(); ?>
<div class="project small">
<a href="<?php the_permalink(); ?>" rel="bookmark" >
<?php the_post_thumbnail("ttrust_one_fourth_cropped", array('class' => 'thumb', 'alt' => ''.get_the_title().'', 'title' => ''.get_the_title().'')); ?>
<span class="title"><span><?php the_title(); ?></span></span>
<?php endwhile; endif; ?>
<?php } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.