Need help with foreach and query_posts example
-
Running into a snag with the following code:
global $post; $terms = get_the_terms( $post->ID , 'relationship'); $do_not_duplicate[] = $post->ID; if(!empty($terms)){ foreach ($terms as $term) { query_posts( array( 'relationship' => $term->slug, 'caller_get_posts' => 1, 'orderby' => 'rand', 'showposts' => 3, 'post__not_in' => $do_not_duplicate ) ); if(have_posts()){ while ( have_posts() ) : the_post(); $do_not_duplicate[] = $post->ID; ?> <div class="related"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_post_thumbnail('product-thumbnail'); ?></a></div> <?php endwhile; wp_reset_query(); } } }
It calls up 3 posts per tag. So if the current post has 4 tags, I get 12 thumbnails. I only want 3 thumbnails no matter how many tags exist. How can I separate the “for each” from the show posts?
- The topic ‘Need help with foreach and query_posts example’ is closed to new replies.