Advertisement
ericrasch

WordPress: List Custom Post Types by Custom Taxonomies

May 3rd, 2011
2,015
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.06 KB | None | 0 0
  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. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement