Created
December 22, 2018 05:50
-
-
Save thetwopct/435667679862408fe32e8558e46d71dc to your computer and use it in GitHub Desktop.
List all posts by custom taxonomy
This file contains 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><br>'; | |
endwhile; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment