Title: Multiple loops
Last modified: September 1, 2016

---

# Multiple loops

 *  Resolved [sefanjo](https://wordpress.org/support/users/sefanjo/)
 * (@sefanjo)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/multiple-loops-17/)
 * Hi,
 * On my site I need 2 loops running, one loop is just for the normal posts and 
   the other are from a custom post type that I have made.
 * I know there is something to do with WP_Query.
 * Here is a link to the code:
    [http://pastebin.com/dNJw248W](http://pastebin.com/dNJw248W)
 * The first loop runs without any problems,
    but the seconds just displays the 
   Error. (Else statement)
 * I hope someone has a solution to displays the 2nd loop that has to display the
   custom post type.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Moderator [Jose Castaneda](https://wordpress.org/support/users/jcastaneda/)
 * (@jcastaneda)
 * THEME COFFEE MONKEY
 * [10 years, 2 months ago](https://wordpress.org/support/topic/multiple-loops-17/#post-7489504)
 * Hi!
 * Hope you are doing good!
 * I think part of the reason could be because you are not resetting the post data.
   If you look at the documentation page: [https://codex.wordpress.org/Class_Reference/WP_Query](https://codex.wordpress.org/Class_Reference/WP_Query)
 * Quick excerpt:
 *     ```
       $query1 = new WP_Query( $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();
   
       $query2 = new WP_Query( $args2 );
       while ( $query2->have_posts() ) {
       	$query2->the_post();
       	echo '<li>' . get_the_title( $query2->post->ID ) . '</li>';
       }
   
       // Restore original Post Data because we always cleanup after ourselves
       wp_reset_postdata();
       ```
   
 * Hope that helps!
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/multiple-loops-17/#post-7489510)
 * is the custom post type using the default categories or custom taxonomies?
 *  Thread Starter [sefanjo](https://wordpress.org/support/users/sefanjo/)
 * (@sefanjo)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/multiple-loops-17/#post-7489522)
 * The custom post type is using default taxonomies [@michael](https://wordpress.org/support/users/michael/)
 *  Thread Starter [sefanjo](https://wordpress.org/support/users/sefanjo/)
 * (@sefanjo)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/multiple-loops-17/#post-7489524)
 * [@jose](https://wordpress.org/support/users/jose/) Castaneda , I’ve allready 
   tried to rest it but that did not help..

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Multiple loops’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [sefanjo](https://wordpress.org/support/users/sefanjo/)
 * Last activity: [10 years, 2 months ago](https://wordpress.org/support/topic/multiple-loops-17/#post-7489524)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
