WordPress.org

Forums

[resolved] Query posts displaying posts twice (5 posts)

  1. peterbra
    Member
    Posted 3 years ago #

    Hi,
    I'm puzzled with one problem. I use query posts to get posts from 2 categories and then display the title.
    I am using this code:

    [code moderated according to Forum Rules - please use the pastebin]

    I want to display posts that are belonging only TO BOTH categories (Day and Circuit) and since I'm using some div holders so I need to determine if there are posts in both categories or not, so what this does:
    1. Checks (counts) to see if there are posts belonging to both categories
    2. If no posts are assigned to both categories, move to next
    3. If posts exist in both categories - display them.

    Now the problem is that I am seeing the posts displayed twice ? Why is this ?

  2. Adrian Wong
    Member
    Posted 3 years ago #

    Hi peterbra,

    That's a long line of code you've have there.
    I did not check it out fully but I guess you may have to put the following rewind_posts(); function after all the wp_reset_query(); .

    If that did not work, try using different circuit name for the different categories.
    Example:

    <?php wp_reset_query();
    $circuit_a_count = 0;
    $circuit_b_count = 0;
    $circuit_c_count = 0;
    $circuit_d_count = 0;
    $circuit_e_count = 0;
    $circuit_f_count = 0;
    ?>

    next category can be:

    <?php wp_reset_query();
    $circuit_g_count = 0;
    $circuit_h_count = 0;
    $circuit_i_count = 0;
    $circuit_j_count = 0;
    $circuit_k_count = 0;
    $circuit_l_count = 0;
    ?>
  3. peterbra
    Member
    Posted 3 years ago #

    flatwhitestudio, I've tried changing counter vars already and it didn't help.
    Placing rewind_posts(); is just creating infinite loop :(

    Thanks for tips anyway ;)

  4. peterbra
    Member
    Posted 3 years ago #

    Just noticed that code was deleted by forum rules :)
    Here is the pastebin code:
    Click Here

  5. peterbra
    Member
    Posted 3 years ago #

    I'm blind. Since this is a loop within a loop it was calling posts twice, so I just reset the posts after first query and it's all good now !

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.