Created
April 23, 2020 16:48
-
-
Save wpjess/1915d2f18e7f2e0a215cc417eb6d1866 to your computer and use it in GitHub Desktop.
Loop by taxonomy term
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
<?php | |
$_terms = get_terms( array('TAXONOMY-NAME') ); | |
foreach ($_terms as $term) : | |
$term_slug = $term->slug; | |
$_posts = new WP_Query( array( | |
'post_type' => 'POST-TYPE-NAME', | |
'posts_per_page' => 200, | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'TAXONOMY-NAME', | |
'field' => 'slug', | |
'terms' => $term_slug, | |
), | |
), | |
)); | |
if( $_posts->have_posts() ) : | |
echo '<h3>'. $term->name .'</h3>'; | |
echo '<div class="row">'; | |
while ( $_posts->have_posts() ) : $_posts->the_post(); | |
?> | |
<div class="col-sm-6"> | |
<h4><?php the_title(); ?></h4> | |
<p><?php echo get_post_meta( get_the_ID(), 'url', true ); ?></p> | |
</div> | |
<?php | |
endwhile; | |
echo '</div>'; | |
endif; | |
wp_reset_postdata(); | |
endforeach; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment