Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!

WordPress: List Custom Post Types by Custom Taxonomies

By: ericrasch on May 3rd, 2011  |  syntax: PHP  |  size: 1.06 KB  |  views: 1,285  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. //for a given post type, return all
  3.   $post_type = 'careers';
  4.   $tax = 'career_category';
  5.   $tax_terms = get_terms($tax);
  6.   if ($tax_terms) {
  7.     foreach ($tax_terms as $tax_term) {
  8.       $args=array(
  9.         'post_type' => $post_type,
  10.         "$tax" => $tax_term->slug,
  11.         'post_status' => 'publish',
  12.         'posts_per_page' => -1,
  13.         'orderby' => 'title',
  14.         'order' => 'ASC',
  15.         'caller_get_posts'=> 1
  16.       ); // END $args
  17.  
  18.       $my_query = null;
  19.       $my_query = new WP_Query($args);
  20.       if( $my_query->have_posts() ) {
  21.         echo 'List of '.$post_type . ' where the taxonomy <em>'. $tax . '</em>  is <strong>'. $tax_term->name .'</strong>';
  22.         while ($my_query->have_posts()) : $my_query->the_post(); ?>
  23.           <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
  24.           <?php
  25.         endwhile;
  26.       } // END if have_posts loop
  27.       wp_reset_query();
  28.     } // END foreach $tax_terms
  29.   } // END if $tax_terms
  30. ?>
clone this paste RAW Paste Data