WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Comments list not accurate (4 posts)

  1. xyren
    Member
    Posted 5 years ago #

    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..

    sample....

    <?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(); ?>
    </div>

    <? //next wordpress query
    if(in_category('Bands')):
    $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;
    endif;
    ?>

    <?php comments_template(); ?>

    <?php endwhile;
    endif;
    ?>

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

    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.

  3. xyren
    Member
    Posted 5 years ago #

    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...

  4. xyren
    Member
    Posted 5 years ago #

    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.. :)

Topic Closed

This topic has been closed to new replies.

About this Topic