Skip to content

Instantly share code, notes, and snippets.

@mzo84
Created August 16, 2016 06:34
Show Gist options
  • Save mzo84/7bce0b484005b59af1c34b0aea2ba745 to your computer and use it in GitHub Desktop.
Save mzo84/7bce0b484005b59af1c34b0aea2ba745 to your computer and use it in GitHub Desktop.
Using WP_Query to create and customize multiple loops.
<?php // Loop 1
$ rst_query = new WP_Query('cat=-1'); // exclude category
while($ rst_query->have_posts()) : $ rst_query->the_post();
...
endwhile;
wp_reset_postdata(); // reset the query
// Loop 2
$second_query = new WP_Query('cat=-2'); // exclude category
while($second_query->have_posts()) : $second_query->the_post();
...
endwhile;
wp_reset_postdata(); // reset the query
// Loop 3
$third_query = new WP_Query('cat=-3'); // exclude category
while($third_query->have_posts()) : $third_query->the_post();
...
endwhile;
wp_reset_postdata(); // reset the query
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment