Skip to content

Instantly share code, notes, and snippets.

@krishna19
Created November 22, 2015 05:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krishna19/ec1665d37e2f4b1bfdd0 to your computer and use it in GitHub Desktop.
Save krishna19/ec1665d37e2f4b1bfdd0 to your computer and use it in GitHub Desktop.
Loop through sutom taxomonies and display posts
<?php
//this loop returns all movies separated by genres they belong to
$post_type = 'brand';
$tax = 'division';
$tax_terms = get_terms($tax);
if ($tax_terms) {
foreach ($tax_terms as $tax_term) {
$args=array(
'post_type' => $post_type,
"$tax" => $tax_term->slug,
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo '<li><a href="/division/' . $tax_term->slug . '">' . $tax_term->name . '</a>';
echo '<ul>';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php endwhile;
echo '</ul>';
echo '</li>';
}
wp_reset_query();
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment