Skip to content

Instantly share code, notes, and snippets.

@anythinggraphic
Last active October 18, 2017 13:55
Show Gist options
  • Save anythinggraphic/f2ac7ba03b34ac65c38b13f2334d2feb to your computer and use it in GitHub Desktop.
Save anythinggraphic/f2ac7ba03b34ac65c38b13f2334d2feb to your computer and use it in GitHub Desktop.

Revisions

  1. anythinggraphic revised this gist Oct 18, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion loop.php
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    <?php

    /* @link TBA
    /* Within your custom loop, get all taxonmies for a custom post type (CPT) and display each post within those taxonomies
    /* Within your custom loop, get all taxonomies for a custom post type (CPT) and display each post within those taxonomies
    ----------------------------------------------------------------------------------------*/

    $post_type = 'your_cpt_name';
  2. anythinggraphic created this gist Oct 18, 2017.
    48 changes: 48 additions & 0 deletions loop.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    <?php

    /* @link TBA
    /* Within your custom loop, get all taxonmies for a custom post type (CPT) and display each post within those taxonomies
    ----------------------------------------------------------------------------------------*/

    $post_type = 'your_cpt_name';

    // Get all of the taxonomies for this post type
    $taxonomies = get_object_taxonomies((object) array( 'post_type' => $post_type )); ?>

    <div class="wrap">
    <?php foreach( $taxonomies as $taxonomy ) :
    // Gets every "category" (term) in this taxonomy to get the posts assigned to it
    $terms = get_terms( $taxonomy );

    foreach( $terms as $term ) :
    $args = array(
    'taxonomy' => $taxonomy,
    'term' => $term->slug,
    'order' => 'ASC',
    'posts_per_page' => -1,
    );

    $loop = new WP_Query($args);

    if ($loop->have_posts()) : ?>
    <div class="row">
    <h4 itemprop="headline">
    <?php echo $term->name; ?>
    </h4>
    <div class="one-third-wrapper">
    <?php while ($loop->have_posts()) : $loop->the_post(); ?>
    <article <?php post_class('one-third') ?>>
    <a href="<?php echo get_the_permalink(); ?>">
    <?php if (has_post_thumbnail()) {
    the_post_thumbnail();
    } ?>
    <?php the_title(); ?>
    </a>
    </article>
    <?php endwhile; ?>
    </div>
    </div>
    <?php endif;
    endforeach;
    endforeach; ?>
    </div>