Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ashleycam3ron/7b71e0d10427b3d1bb81eafdf348380b to your computer and use it in GitHub Desktop.
Save ashleycam3ron/7b71e0d10427b3d1bb81eafdf348380b to your computer and use it in GitHub Desktop.
<?php /* Loop through Promotion and Display Vendors as heading and promo posts within */
$post_type = 'promotion';
// Get all the taxonomies for this post type
$object = 'post';
$output = 'objects';
$taxonomies = get_object_taxonomies( $object, $output );
$exclude = array( 'post_tag','post_format','category' );
foreach( $taxonomies as $taxonomy ) :
if( in_array( $taxonomy->name, $exclude ) ) {
continue;
}
// Gets every "category" (term) in this taxonomy to get the respective posts
$terms = get_terms( array(
'taxonomy' => $taxonomy->name,
'hide_empty' => true,
//'exclude' => array( 97 ),
) );
foreach( $terms as $term ) : ?>
<div class="row header clear"><h2 id="<?php echo $term->slug; ?>"><?php echo $term->name; ?> </h2></div>
<?php $args = array(
'post_type' => $post_type,
'posts_per_page' => -1, //show all posts
'tax_query' => array(
array(
'taxonomy' => 'vendors',
'field' => 'slug',
'terms' => $term->slug,
)
)
);
$posts = new WP_Query($args);
if( $posts->have_posts() ):
$count = 1;
while( $posts->have_posts() ) : $posts->the_post(); ?>
<article class="col-sm-6">
<h4>Promotion <?php echo $count++; ?></h4>
<?php get_template_part( 'template-parts/content-promos' ); ?>
</article>
<?php endwhile; endif; ?>
<?php endforeach;
endforeach; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment