Support » Fixing WordPress » Comments list not accurate

  • Resolved xyren


    I have a custom single.php which is content of a lot of wordpress query ‘wp_query’. all query goes perfect what i want to happen.

    the problem is this. after a lot of query the comments respond in the last query happen.

    I have resolve this issue already using the clone function by PHP5. but it seems the page loading too slow…

    Please help me so my site do works perfect.. thank you..


    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div class=”page_post_content” id=”post-<?php the_ID(); ?>”>
    <div id=”title”>
    <h2><?php the_title(); ?></h2>
    <?php the_time(‘F.d.Y’) ?> | <?php the_time() ?> |
    by: <?php the_author(); ?>

    <? //next wordpress query
    $band_members = new WP_Query(); $bandname_id=get_cat_id($the_band_title); $profile_id=get_cat_id(‘profiles’); $band_members->query(array(‘category__and’ => array($bandname_id,$profile_id))); while($band_members->have_posts()) : $band_members->the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <h2><?php the_content(); ?></h2>
    <?php endwhile;

    <?php comments_template(); ?>

    <?php endwhile;

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Samuel Wood (Otto)

    (@otto42) Admin

    When you call the_post on your query, you overwrite the $post global which the comments template needs to get the comments.

    Before your custom query, save the post data like so:

    global $post;
    $saved_post = $post;

    Then restore it before calling the comments template:
    $post = $saved_post;

    That should do the trick.

    Thanks for help…

    Its working but still have bug.
    the comments list perfectly…
    but if i add a new comments… still appear in the last query.

    i think its in function of..
    — comment_id_fields();

    which appear in html source
    <input type=’hidden’ name=’comment_post_ID’ value=’49’ id=’comment_post_ID’ />
    the ’49’ is the last query..
    seem will will ’42’ which is the Main query…

    Thanks dude…
    because of that i have an idea…
    so i solve it..

    within the functions of comments..
    it declare the global $id which is replresent the POST id..
    so i declare the global id in my comments.php and same in my comments-form.php

    <?php global $id; ?>
    <?php $id=$post->ID; ?>

    Thanks for helping me…

    Check this link

    for the success i have.. 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Comments list not accurate’ is closed to new replies.