Advertisement
Guest User

loop in posts with same taxonomy term

a guest
Aug 18th, 2011
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 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.  
  26. my divs and stuff...
  27.  
  28. <?php $found_none = '';
  29. endwhile;
  30. }
  31. }
  32. }
  33. if ($found_none) {
  34. echo $found_none;
  35. }
  36. $post = $backup; // copy it back
  37. wp_reset_query(); // to use the original query again
  38. ?>
  39. </div> <!-- end thumbnail area -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement