Last active
December 18, 2015 10:49
-
-
Save isGabe/5771118 to your computer and use it in GitHub Desktop.
WordPress: CPT Archive Organized by Taxonomy Term #snippet #WordPress
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
<?php | |
$tax_name = 'tax_name'; | |
$terms = get_terms($tax_name); | |
$count = count($terms); | |
if ( $count > 0 ){ | |
foreach ( $terms as $term ) { | |
echo '<section class="' . $term->name . '">'; | |
echo '<h2 class="section-title">' . $term->name . '</h2>'; | |
echo '<ul>'; | |
$loop = new WP_Query( array( | |
'post_type' => 'post_type', | |
'post_per_page' => 10, | |
'orderby' => 'menu_order', | |
'order' => 'ASC', | |
'tax_query' => array( | |
array( | |
'taxonomy' => $tax_name, | |
'field' => 'id', | |
'terms' => $term->term_id | |
) | |
) | |
)); | |
// the loop | |
while ($loop->have_posts()) : $loop->the_post(); | |
// put your loop content here | |
echo '<li>' . get_the_title() . '</li>'; | |
endwhile; | |
// reset $post so that the rest of the template is in the original context | |
wp_reset_postdata(); | |
echo '</ul>'; | |
echo '</section>'; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment