need some help for a special custom query.
I'm trying to build a single query to retrieve some posts from different categories instead of running several loop.
Is there a clean way to do that?
I have 3 categories (catA, catB and catC)
and I retrieve one random post per each category using three queries like this one:
//
// Loop A
//
function loop_A(){
// The In Production Shows Query
$args = array(
'posts_per_page' => 1,
'category_name' => 'catA',
'orderby' => 'rand',
'post_status' => 'publish' );
$loop_A = new WP_Query( $args );
echo '<ul>';
// The Loop
while ( $loop_A->have_posts() ) : $loop_A->the_post();
?>
<li>
<a href="<?php echo the_permalink(); ?>" title="<?php echo the_title_attribute(); ?>">
<?php echo the_title(); ?>
</a>
</li>
<?php
endwhile;
echo '</ul>';
// Reset Post Data
wp_reset_postdata();
}
I probably have to add five categories in my page, so I'm trying to figure out how to avoid eight different queries running on a single page.
Hope some of you can help! I really appreciate every suggestion!
Thanks Bye Carletto