Last active
December 1, 2019 20:26
-
-
Save omurphy27/b07956479ab1606af1821b64802544ae to your computer and use it in GitHub Desktop.
Wordpress WP - Loop through all Terms associated with CPT Taxonomy and their Associated Posts
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' => 'dojo_category', | |
) ); | |
foreach( $terms as $term ) : ?> | |
<div class="dojo-location-block"> | |
<h2><?php echo $term->name; ?></h2> | |
<?php $posts = new WP_Query( "taxonomy=dojo_category&term=$term->slug&posts_per_page=-1" ); | |
if( $posts->have_posts() ): while( $posts->have_posts() ) : $posts->the_post(); ?> | |
<div class="dojo-block clearfix"> | |
<div class="col-md-6"> | |
<p> | |
<strong><?php the_title(); ?></strong> | |
</p> | |
<?php the_field('content_left'); ?> | |
</div> | |
<div class="col-md-6 text-right"> | |
<?php the_field('content_right'); ?> | |
</div> | |
</div> | |
<?php endwhile; endif; ?> | |
</div> | |
<?php endforeach;?> | |
<?php wp_reset_postdata(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment