Support » Themes and Templates » multiple loop and duplicate post problem

  • Hi all, i have the first post, then i get other posts from a category. The problem is that if i get only the first post is all ok, if get 2 or more posts these will be duplicated. Here is my code:

    in the first div

    $my_query = new WP_Query(‘showposts=1&cat=-6,-8’);
    while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate = $post->ID;?>

    in the div where posts are duplicated:

    $catname = catname;
    $wp_query = new WP_Query();
    <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
    <?php if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>

Viewing 7 replies - 1 through 7 (of 7 total)
  • if you have read this:
    read it again, it explains how to do the ‘$do_not_duplicate’ method for more than one post.

    Hi alchymyth and thank you for your help!!
    I have read that but i can’t get it working.
    I didn’t understand if in my situation i need to modify the first or second query. I tried to change the second but i get an array error.

    as far as i understand, you need to modify both queries.

    just re-read the ‘replace … with …’ instructions after these lines:

    Note for Multiple Posts in the First Category

    If posts_per_page=2 or more, you will need to alter the code a bit. The variable $do_not_duplicate needs to be changed into an array as opposed to a single value.

    you couls also paste the whole code of your file into a and post the link to it here.

    I tested and tried the code. This is the situation:
    I have now a first part of the home page where i get the latest post without calling it by category.
    Then i have 3 columns where i get all other posts by category.
    What i want to do is insert other 3 posts without category after the first post and before the three columns.
    I tried to do this with the query explained in the codex.
    What happened?
    I first inverted the query. Ok, posts are not duplicated but in the column where i call posts by category the query seems to be ignored, i have all posts from each category!
    Help please! Thanks.

    i can only repeat:

    you could paste the whole code of your file into a and post the link to it here.

    someone might have a look at it and come up with an idea…

    it could sometimes help to post a link to the ‘trouble’ site.

    WP Voyager


    @sandeep1414: PLEASE stop interfering with other people’s threads! As I and alchymyth have said before in similar situations, your post has nothing at all to do with the question at hand in this thread.

    You must rely on the merit of your own thread to get your question answered. I see from your link that your thread has no tags. Adding tags to your thread will help people find it better. But hitchhiking on another person’s thread is just inconsiderate.


Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘multiple loop and duplicate post problem’ is closed to new replies.