WordPress.org

Ready to get started?Download WordPress

Forums

multiple loop and duplicate post problem (8 posts)

  1. antonio nardelli
    Member
    Posted 4 years ago #

    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

    <?php
    $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:

    <?php
    $catname = catname;
    $wp_query = new WP_Query();
    $wp_query->query('category_name='.$catname.'&showposts=5'.'&paged='.$paged);
    ?>
    <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
    <?php if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>

  2. alchymyth
    The Sweeper & Moderator
    Posted 4 years ago #

    if you have read this:
    http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action
    read it again, it explains how to do the '$do_not_duplicate' method for more than one post.

  3. antonio nardelli
    Member
    Posted 4 years ago #

    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.

  4. alchymyth
    The Sweeper & Moderator
    Posted 4 years ago #

    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 http://wordpress.pastebin.com/ and post the link to it here.

  5. antonio nardelli
    Member
    Posted 4 years ago #

    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.

  6. alchymyth
    The Sweeper & Moderator
    Posted 4 years ago #

    i can only repeat:

    you could paste the whole code of your file into a http://wordpress.pastebin.com/ 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.

  7. sandeep1414
    Member
    Posted 4 years ago #

    @alchymyth Bro plz help me with this thread...

    http://wordpress.org/support/topic/391570?replies=1

  8. WP Voyager
    Member
    Posted 4 years ago #

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

    Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic