Skip to main content
4 of 4
Rollback to Revision 2
200_success
  • 145.6k
  • 22
  • 191
  • 481

WordPress: multiple loops

I have two loops on my page - each with their own category. It works, but I don't know if this is the best practice as I'm pretty new to this stuff.

<?php $my_query = new WP_Query( 'category_name=news&posts_per_page=3' );
        while ( $my_query->have_posts() ) : $my_query->the_post();
                $do_not_duplicate[] = $post->ID; ?>
                <!-- Do stuff... -->
<?php get_template_part( 'content', get_post_format() ); ?>

<?php endwhile; ?>

<?php $second_query = new WP_Query( 'category_name=reviews&posts_per_page=4' );
        while ( $second_query->have_posts() ) : $second_query->the_post();
                $do_not_duplicate[] = $post->ID; ?>
                <!-- Do stuff... -->
<?php get_template_part( 'content', get_post_format() ); ?>

<?php endwhile; ?>
alexwc_
  • 249
  • 3
  • 12