I'm trying to display related posts by a custom taxonomy (product_tags) in a custom post type (products). The following code works, but it ignores posts_per_page.
Any ideas?
global $post;
$terms = get_the_terms( $post->ID , 'product_tags', 'string');
$do_not_duplicate[] = $post->ID;
if(!empty($terms)){
echo '<strong>Related Products</strong>';
foreach ($terms as $term) {
query_posts( array(
'post_type' => 'products',
'product_tags' => $term->slug,
'posts_per_page' => 3,
'ignore_sticky_posts' => 1,
'orderby' => 'rand',
'post__not_in' => $do_not_duplicate) );
if(have_posts()) {
while ( have_posts() ) : the_post(); $do_not_duplicate[] = $post->ID; ?>
<div class="single_related">
<?php if (has_post_thumbnail()) { ?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<?php the_post_thumbnail( 'related_sm', array('alt' => get_the_title()) ); ?>
</a>
<?php } else { ?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
<?php } ?>
</div>
<?php endwhile; wp_reset_query();
}
}
}