Advertisement
Guest User

Query for multiple tags, how to exclude duplicates

a guest
Oct 10th, 2011
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1.         <?php global $post;
  2.         $nextTagThumb='-1';
  3.         $yourCategory = '4';
  4.         $tags = wp_get_post_tags($post->ID);
  5.         foreach ($tags as $tag) :?>
  6.  
  7.         <?php
  8.         if ($tags) {
  9.         $what_tag = $tags[($nextTagThumb+'1')]->term_id;
  10.         $args=array(
  11.         'category__in' => array($yourCategory),
  12.         'tag__in' => array($what_tag),
  13.         'post__not_in' => array($post->ID, $do_not_duplicate),
  14.         'showposts'=>20,
  15.         'caller_get_posts'=>1
  16.         );
  17.         $my_query = new WP_Query($args); $do_not_duplicate = array();
  18.         if( $my_query->have_posts() ) {
  19.         while ($my_query->have_posts()) : $my_query->the_post(); if (!in_array($post->ID, $do_not_duplicate)) ?>
  20.  
  21.         <li class="post-<?php the_ID(); ?>">
  22.         <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><span class="sidebar-post-title"><?php the_title(); ?></span>
  23.         <span class="sidebar-post-thumb"><img src="<?php echo get_post_meta($post->ID, "sidebar-thumb", true);?>" /></span>
  24.         </a>
  25.         </li>
  26.         <?php endwhile;
  27.         }
  28.         wp_reset_query();
  29.         $nextTagThumb = ($nextTagThumb+1);
  30.         }
  31.         ?>
  32.         <?php endforeach; ?>
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement