Skip to content

Instantly share code, notes, and snippets.

@FriendlyWP
Last active December 27, 2015 14:39
Show Gist options
  • Save FriendlyWP/7341853 to your computer and use it in GitHub Desktop.
Save FriendlyWP/7341853 to your computer and use it in GitHub Desktop.
List custom post types organized by taxonomy. Show taxonomy titles. From http://wordpress.stackexchange.com/a/66232/16
$custom_terms = get_terms('custom_taxonomy');
foreach($custom_terms as $custom_term) {
wp_reset_query();
$args = array(
'post_type' => 'custom_post_type',
'tax_query' => array(
array(
'taxonomy' => 'custom_taxonomy',
'field' => 'slug',
'terms' => $custom_term->slug,
),
),
);
$loop = new WP_Query($args);
if($loop->have_posts()) {
echo '<h2>'.$custom_term->name.'</h2>';
while($loop->have_posts()) : $loop->the_post();
echo '<a href="'.get_permalink().'">'.get_the_title().'</a>';
endwhile;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment