Advertisement
Guest User

Same taxonomy term

a guest
Sep 1st, 2011
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.20 KB | None | 0 0
  1. <?php
  2.     //for in the loop, display all "content", regardless of post_type,
  3.     //that have the same custom taxonomy (e.g. genre) terms as the current post
  4.     $backup = $post;  // backup the current object
  5.     $found_none = '';
  6.     $taxonomy = 'kund';//  e.g. post_tag, category, custom taxonomy
  7.     $param_type = 'kund'; //  e.g. tag__in, category__in, but genre__in will NOT work
  8.     $post_types = get_post_types( array('public' => true), 'names' );
  9.     $tax_args=array('orderby' => 'none');
  10.     $tags = wp_get_post_terms( $post->ID , $taxonomy, $tax_args);
  11.     if ($tags) {
  12.       foreach ($tags as $tag) {
  13.         $args=array(
  14.           "$param_type" => $tag->slug,
  15.           'post__not_in' => array($post->ID),
  16.           'post_type' => $post_types,
  17.           'showposts'=>-1,
  18.           'caller_get_posts'=>1
  19.     );
  20.     $my_query = null;
  21.     $my_query = new WP_Query($args);
  22.     if( $my_query->have_posts() ) {
  23.       while ($my_query->have_posts()) : $my_query->the_post(); ?>
  24.        
  25.             -- My stuff here --
  26.            
  27.         <?php $found_none = '';
  28.         endwhile;
  29.         }
  30.       }
  31.     }
  32.     if ($found_none) {
  33.     echo $found_none;
  34.     }
  35.     $post = $backup;  // copy it back
  36.     wp_reset_query(); // to use the original query again
  37.     ?>
  38.     </div> <!-- end thumbnail area -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement