Support » Fixing WordPress » Query posts displaying posts twice

  • Resolved peterbra


    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 ?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Adrian Wong


    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.

    <?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;

    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 😉

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

    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 !

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Query posts displaying posts twice’ is closed to new replies.