- don’t use
query_posts()
for secondary loops – When should you use WP_Query vs query_posts() vs get_posts()? - get only top level categories
- using
'category__in'
should not get posts from child categories
for example:
<?php
$cats = get_categories('parent=0');
foreach ($cats as $cat) :
$args = array(
'posts_per_page' => 1,
'category__in' => array( $cat->term_id ) );
$top_cat_query = new WP_Query($args);
if( $top_cat_query->have_posts() ) while( $top_cat_query->have_posts() ) :
$top_cat_query->the_post();
//output
endwhile; wp_reset_postdata();
//..etc..
endforeach;
?>
(not tested)