Skip to content

Instantly share code, notes, and snippets.

@jackabox
Created January 5, 2015 15:26
Show Gist options
  • Select an option

  • Save jackabox/702cac3cffb0fae1e743 to your computer and use it in GitHub Desktop.

Select an option

Save jackabox/702cac3cffb0fae1e743 to your computer and use it in GitHub Desktop.
Custom posts, by custom taxonomy.
<?php
$categories = get_terms( 'service-category' );
foreach ( $categories as $category ) {
$services = new WP_Query(
array(
'post_type' => 'services',
'showposts' => -1,
'tax_query' => array(
array(
'taxonomy' => 'service-category',
'terms' => array( $category->slug ),
'field' => 'slug'
)
)
)
);
?>
<div class="service__list-box">
<h3><?php echo $category->name; ?></h3>
<ul>
<?php while ($services=->have_posts()) : $services=->the_post(); ?>
<li><?php the_title(); ?></li>
<?php endwhile; ?>
</ul>
</div>
<?php
// Reset things, for good measure
$services = null;
wp_reset_postdata();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment