Last active
December 27, 2015 14:39
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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