1.     <div id="single" class="ad-gallery">
  2.   <div class="ad-image-wrapper">
  3.   </div>
  4.   <div id="description"></div>
  5.   <div class="ad-controls">
  6.   </div>
  7.   <div class="ad-nav">
  8.     <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
  9.     <?php $category = get_the_category($post->ID); ?>
  10.     <?php $termlist =  wp_get_post_terms( $_POST['id'], 'clients', array("fields" => "all"));  ?>
  11.     <?php $client = get_terms('clients', 'orderby=count&hide_empty=0'); ?>
  12.     <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full'); ?>
  13.     <?php $image_thumb = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail'); ?>
  14.     <div class="ad-thumbs">
  15.       <ul class="ad-thumb-list">
  16.         <li>
  17.           <a href="<?php echo $image[0]; ?>">
  18.             <img src="<?php echo $image_thumb[0]; ?>" title="<?php echo the_title(); ?>" data-ad-desc="<?php echo the_content(); ?>">
  19.           </a>
  20.         </li>
  21.     <?php endwhile;
  22.         endif;
  23.     ?>
  24.     <?php
  25.             global $post;
  26.             $terms = get_the_terms( $_POST['id'] , 'clients');
  27.             $do_not_duplicate[] = $_POST['id'];
  28.            
  29.             if(!empty($terms)){
  30.                 foreach ($terms as $term) {
  31.                     query_posts( array(
  32.                     'clients' => $term->slug,
  33.                     'posts_per_page' => -1,
  34.                     'caller_get_posts' => 1,
  35.                     'post__not_in' => $do_not_duplicate ) );
  36.                     if(have_posts()){
  37.                         while ( have_posts() ) : the_post(); $do_not_duplicate[] = $post->ID; ?>
  38.                         <?php print_r($post);exit(); ?>
  39.                             <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full'); ?>
  40.                             <?php $image_thumb = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail'); ?>
  41.                         <a href="<?php echo $image[0]; ?>">
  42.                             <img src="<?php echo $image_thumb[0]; ?>" title="<?php echo the_title(); ?>" data-ad-desc="<?php echo the_content(); ?>">
  43.                         </a>
  44.                         <?php endwhile; wp_reset_query();
  45.                     }
  46.                 }
  47.             }
  48.     ?>
  49.       </ul>
  50.     </div>
  51.   </div>
  52. </div>