Advertisement
joelgoodman

Category list from custom taxonomies.

Mar 12th, 2011
778
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.81 KB | None | 0 0
  1. <?php
  2.     $tags = wp_get_post_terms($post->ID, 'client_name');
  3.     $args = array (
  4.                 'tax_query' => array (
  5.                     'taxonomy' => 'client_name',
  6.                     'terms' => $tags[0]->term_id
  7.                     ),
  8.                 'post_type' => 'project'
  9.                 );
  10.    
  11.     $query = new WP_query($args);
  12.         if ( $query->have_posts() ) : {
  13.             while ( $query->have_posts()) : $query->the_post();
  14.             $postcats = get_the_term_list($post->ID,'project_type','','','');
  15.                 if ($postcats) {
  16.                         foreach($postcats as $cat) {
  17.                             $all_cats_arr[] = $cat -> name; //USING JUST $cat MAKING $all_cats_arr A MULTI-DIMENSIONAL ARRAY, WHICH DOES WORK WITH array_unique
  18.                         }
  19.                     }
  20.                 endwhile;
  21.                 }
  22.             endif;
  23.     $cats_arr = array_unique($all_cats_arr); //REMOVES DUPLICATES
  24.     echo '<li>'.print_r($cats_arr, true).'</li>'; //OUTPUT FINAL CATS
  25.     wp_reset_query();
  26. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement