I'm building a post grid on my front page and I'd like to show one random post per CPT. At the moment, CPT are queried out in a query array:
<?php
$c = 1; //init counter
$bpr = 3; //boxes per row
$wp_query = new WP_Query(array('showposts' => 9, 'orderby'=> 'rand', 'post_type' => array('productions', 'plays', 'movies', 'theatres', 'directors', 'artists', 'countries', 'events', 'grades')));
while( have_posts() ) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<p><?php $post_type = get_post_type_object( get_post_type($post) ); echo $post_type->label ; ?></p>
<a href="<?php the_permalink() ?>" rel="bookmark">
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail('thumbnail');
} else { ?>
<img src="<?php bloginfo('template_directory'); ?>/img/fallback_image.jpg" alt="<?php the_title(); ?>" />
<?php } ?>
</a>
</div>
<?php
if($c == $bpr) :
?>
<div class="clr"></div>
<?php
$c = 0;
endif;
?>
<?php
$c++;
endwhile;
?>
So the problem with this array is that it starts to dublicate the CPT's when I query them, sometimes even it queries 4 random posts from CPT.
One solution would be to create 9 different queries - one for each CPT, but this seems to be overkill for the front page.
Is there a way to really only query 1 random post per CPT in a way that wouldn't affect the page loading time so much?