Title: Multiple Posts &#8212; Restoring first query
Last modified: August 19, 2016

---

# Multiple Posts — Restoring first query

 *  Resolved [valuxes](https://wordpress.org/support/users/valuxes/)
 * (@valuxes)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/multiple-posts-restoring-first-query/)
 * I searched the codex and existing posts. This one in particular seemed to be 
   what I am looking for: [http://wordpress.org/support/topic/267056?replies=5](http://wordpress.org/support/topic/267056?replies=5)
 * 1. Save the original query in a temp_query var
    <?php $temp_query = clone $wp_query;?
   >
 * 2. Do a new WP_query to extract what I want and display these posts (just the
   titles)
    <?php $my_query = new WP_Query(array( ‘order_by’=>date, ‘order’=>’DESC’,));?
   >
 * 3. Restore the original query so the comments associated with the original post
   can display
    <?php $wp_query = clone $temp_query; ?>
 * However, I keep getting the comments of the last post in the new WP_query (in
   item 2)
 * Here is a link to my page: [http://www.photoxels.com/canon-s90-review-digitalcamerareview/](http://www.photoxels.com/canon-s90-review-digitalcamerareview/)
 * There should be no comment associated with the post currently displayed. The 
   5 comments come from the last post from the table just before the comments.
 * Any help is appreciated. Thanks!

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

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/multiple-posts-restoring-first-query/#post-1284889)
 * Please paste all the code from the theme template file (probably index.php) that
   is displaying those posts into a pastebin such as [wordpress.pastebin.ca](http://wordpress.pastebin.ca),
   and report the link back here. Maybe someone can spot your problem. Thanks.
 *  Thread Starter [valuxes](https://wordpress.org/support/users/valuxes/)
 * (@valuxes)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/multiple-posts-restoring-first-query/#post-1285166)
 * [http://wordpress.pastebin.ca/1699336](http://wordpress.pastebin.ca/1699336)
 * Basically, I display a post, then do the above code to fetch all posts that match
   a couple of custom fields and display these in a table.
 * The Comments should apply to the original post displayed, but it is currently
   always referencing the last post in the table.
 * I have a feeling it has nothing to do with saving/restoring $wp_query but rather
   that all the comments from all matching posts are retrieved when I do the query
   to populate the table. Maybe I need to re-retrieve the comments after restoring
   $wp_query… how 🙁
 * Thanks for any help!
 *  Thread Starter [valuxes](https://wordpress.org/support/users/valuxes/)
 * (@valuxes)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/multiple-posts-restoring-first-query/#post-1285167)
 * I tried:
 *     ```
       $wp_comments = null;
       ```
   
 * but still same result…
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/multiple-posts-restoring-first-query/#post-1285168)
 * Not too sure why you even need line 1 or lines 55 and 56.
 * Maybe this at the end there will resolve your problem:
 *     ```
       wp_reset_query();  // Restore global post data stomped by the_post().
       ```
   
 *  Thread Starter [valuxes](https://wordpress.org/support/users/valuxes/)
 * (@valuxes)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/multiple-posts-restoring-first-query/#post-1285185)
 * MichaelH,
 * It works! You rock!
 * Wanting to learn more about wp_reset_query(), I googled it and found this link:
 * [http://www.wordpressurecooker.com/tag/wp_reset_query/](http://www.wordpressurecooker.com/tag/wp_reset_query/)
 * Thanks again! Need any photo/camera help, drop me a line.
 * V

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

The topic ‘Multiple Posts — Restoring first query’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 2 participants
 * Last reply from: [valuxes](https://wordpress.org/support/users/valuxes/)
 * Last activity: [16 years, 6 months ago](https://wordpress.org/support/topic/multiple-posts-restoring-first-query/#post-1285185)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
