• Resolved valuxes

    (@valuxes)


    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

    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/

    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)
  • 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, and report the link back here. Maybe someone can spot your problem. Thanks.

    Thread Starter valuxes

    (@valuxes)

    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

    (@valuxes)

    I tried:

    $wp_comments = null;

    but still same result…

    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

    (@valuxes)

    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/

    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.