Advertisement
Guest User

wordpress - list custom posts by taxonomy term

a guest
Sep 7th, 2012
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.47 KB | None | 0 0
  1. <?php
  2.                     $post_type = 'menus';
  3.                     $tax = 'menu-type';
  4.                     $tax_terms = get_terms($tax,'hide_empty=0');
  5.                    
  6.                    
  7.                    
  8.                     //list everything
  9.                     if ($tax_terms) {
  10.                       foreach ($tax_terms  as $tax_term) {
  11.                         $args=array(
  12.                           'post_type' => $post_type,
  13.                           "$tax" => $tax_term->slug,
  14.                           'post_status' => 'publish',
  15.                           'posts_per_page' => -1,
  16.                           'caller_get_posts'=> 1
  17.                         );
  18.                    
  19.                         $my_query = null;
  20.                         $my_query = new WP_Query($args);
  21.                         if( $my_query->have_posts() ) {
  22.                           echo "<h2 class=\"category-title\" > $tax_term->name </h2><ul class=\"page-listing\">";
  23.                           while ($my_query->have_posts()) : $my_query->the_post(); ?>
  24.                             <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
  25.                             <?php
  26.                           endwhile;
  27.                          
  28.                          
  29.                         }echo "</ul>";
  30.                         wp_reset_query();
  31.                       }
  32.                     }
  33.                     ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement