Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save carlaizumibamford/71df42552fde3a82178089d976aa8733 to your computer and use it in GitHub Desktop.
Save carlaizumibamford/71df42552fde3a82178089d976aa8733 to your computer and use it in GitHub Desktop.
<?php
// The Query
$query1 = new WPQuery( $args );
// The Loop
while ( $query1->have_posts() ) {
$query1->the_post();
echo '<li>' . get_the_title() . '</li>';
}
/* Restore original Post Data
* NB: Because we are using new WP_Query we aren't stomping on the
* original $wp_query and it does not need to be reset with
* wp_reset_query(). We just need to set the post data back up with
* wp_reset_postdata().
*/
wp_reset_postdata();
/* The 2nd Query (without global var) */
$query2 = new WP_Query( $args2 );
// The 2nd Loop
while ( $query2->have_posts() ) {
$query2->the_post();
echo '<li>' . get_the_title( $query2->post->ID ) . '</li>';
}
// Restore original Post Data
wp_reset_postdata();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment