Skip to content

Instantly share code, notes, and snippets.

@davemac
Last active August 29, 2015 14:07
Show Gist options
  • Save davemac/21c27ef369864e458e18 to your computer and use it in GitHub Desktop.
Save davemac/21c27ef369864e458e18 to your computer and use it in GitHub Desktop.
WordPress list custom post grouped by taxonomy term
<?php
$terms = get_terms( 'sponsor_type', array(
'orderby' => 'id',
) );
?>
<?php
foreach( $terms as $term ) {
$args = array(
'post_type' => 'dmc-sponsor',
'sponsor_type' => $term->slug
);
$query = new WP_Query( $args );
echo'<h2><small>' . $term->name . ' Sponsor</small></h2><hr />';
if ( $term->term_id == '8' || $term->term_id == '9' ) :
echo '<ul class="large-block-grid-4';
else :
echo '<ul class="large-block-grid-5';
endif;
echo ' post-list">';
while ( $query->have_posts() ) : $query->the_post(); ?>
<li>
<p><span class="left"><small>Stream: <?php $term_list = the_terms($post->ID, 'conference_stream'); ?></small></span></p>
<a href="<?php echo esc_url(get_field('dmc_sponsor_website')); ?>"><?php the_post_thumbnail( array( 'width' => 300, 'height' => 150 ) , array( 'class' => 'alignnone' ) ); ?></a>
<div class="post-meta">
<h4><a href="<?php echo esc_url(get_field('dmc_sponsor_website')); ?>"><?php the_title(); ?></a></h4>
<small>Contact <a href="mailto:<?php echo sanitize_email(the_field('dmc_sponsor_contact_email')); ?>?BCC=sponsors@atcevents.com.au&amp;Subject=Information Request from ATC Events Sponsor Page"><?php the_field('dmc_sponsor_contact_name'); ?></a></small>
</div>
</li>
<?php endwhile;
echo '</ul>';
wp_reset_postdata();
} ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment