Title: Query posts displaying posts twice
Last modified: August 20, 2016

---

# Query posts displaying posts twice

 *  Resolved [peterbra](https://wordpress.org/support/users/peterbra/)
 * (@peterbra)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/query-posts-displaying-posts-twice/)
 * 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 ](http://codex.wordpress.org/Forum_Welcome)-
   please use the [pastebin](http://pastebin.com/)]_
 * 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](https://wordpress.org/support/users/flatwhitestudio/)
 * (@flatwhitestudio)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/query-posts-displaying-posts-twice/#post-2079135)
 * 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;
       ?>
       ```
   
 *  Thread Starter [peterbra](https://wordpress.org/support/users/peterbra/)
 * (@peterbra)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/query-posts-displaying-posts-twice/#post-2079137)
 * 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 😉
 *  Thread Starter [peterbra](https://wordpress.org/support/users/peterbra/)
 * (@peterbra)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/query-posts-displaying-posts-twice/#post-2079293)
 * Just noticed that code was deleted by forum rules 🙂
    Here is the pastebin code:
   [Click Here](http://pastebin.com/FJZLUWLP)
 *  Thread Starter [peterbra](https://wordpress.org/support/users/peterbra/)
 * (@peterbra)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/query-posts-displaying-posts-twice/#post-2079409)
 * 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.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [peterbra](https://wordpress.org/support/users/peterbra/)
 * Last activity: [15 years, 1 month ago](https://wordpress.org/support/topic/query-posts-displaying-posts-twice/#post-2079409)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
