Title: My WordPress Loop strange
Last modified: October 1, 2021

---

# My WordPress Loop strange

 *  [lucius100](https://wordpress.org/support/users/lucius100/)
 * (@lucius100)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/my-wordpress-loop-strange/)
 * Here is my looping code in index.php
 * [https://pastebin.com/Y583dXvX](https://pastebin.com/Y583dXvX)
 * Let’s say I have 3 categories
    apple,orange,pear
 * 50 post in apple and orange
    30 post in orange and pear
 * So the new post in index.php should be 80 post, it display correctly 80post, 
   but it didn’t show 30 post from orange and pear, instead 80 post only from apple
   and orange. So there’s a lot of duplicated post 50+30 from apple and orange. 
   I don’t know how this happen.
    -  This topic was modified 4 years, 8 months ago by [t-p](https://wordpress.org/support/users/t-p/).
      Reason: Moved to Fixing WordPress from Developing with WordPress

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [Kuldeep](https://wordpress.org/support/users/soberbanda/)
 * (@soberbanda)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/my-wordpress-loop-strange/#post-14929527)
 * Hey [@lucius100](https://wordpress.org/support/users/lucius100/) 🙂
 * You can use this plugin: [https://wordpress.org/plugins/delete-duplicate-posts/](https://wordpress.org/plugins/delete-duplicate-posts/)
   to help you search and remove duplicate posts/pages and their meta data.
 * Hope that works!
 *  Thread Starter [lucius100](https://wordpress.org/support/users/lucius100/)
 * (@lucius100)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/my-wordpress-loop-strange/#post-14930418)
 * [@soberbanda](https://wordpress.org/support/users/soberbanda/) The problem is
   I don’t have duplicate post in my site, but the post looping show duplicate and
   hide some of my existing post.
 *  [Kuldeep](https://wordpress.org/support/users/soberbanda/)
 * (@soberbanda)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/my-wordpress-loop-strange/#post-14930428)
 * Sorry for that [@lucius100](https://wordpress.org/support/users/lucius100/) 🙁
 * I would recommend going through this: [https://wordpress.stackexchange.com/questions/37155/simply-loop-through-posts](https://wordpress.stackexchange.com/questions/37155/simply-loop-through-posts)
 *  Thread Starter [lucius100](https://wordpress.org/support/users/lucius100/)
 * (@lucius100)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/my-wordpress-loop-strange/#post-14931197)
 * [@soberbanda](https://wordpress.org/support/users/soberbanda/) that method of
   using wp query even worst. I don’t think to loop a simple post in front page 
   required to use wp query. That being said, I don’t think there’s something wrong
   with the code either. Just confused how the heck it happened.
    I mean, I don’t
   have duplicate post in database/admin page, but it’s looping duplicate post in
   front page. I even count the total page with the pagination, it shows correct
   number of my total post. But some of the post not appearing in front page because
   it’s duplicated by other post.
 *  [Kuldeep](https://wordpress.org/support/users/soberbanda/)
 * (@soberbanda)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/my-wordpress-loop-strange/#post-14931584)
 * [@lucius100](https://wordpress.org/support/users/lucius100/) Try reviewing: [https://www.wpbeginner.com/wp-themes/how-to-avoid-duplicate-post-display-with-multiple-loops-in-wordpress/](https://www.wpbeginner.com/wp-themes/how-to-avoid-duplicate-post-display-with-multiple-loops-in-wordpress/)
 * Let’s wait and see if someone more experienced on this can help.
 *  Thread Starter [lucius100](https://wordpress.org/support/users/lucius100/)
 * (@lucius100)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/my-wordpress-loop-strange/#post-14933242)
 * Ok, I finally solved the problem, but I don’t know wtf is going on, lol.
    I research
   more and found this problem with same issues as mine. [https://wordpress.stackexchange.com/questions/364381/unwanted-duplicate-posts-showing-in-pagination-pages](https://wordpress.stackexchange.com/questions/364381/unwanted-duplicate-posts-showing-in-pagination-pages)
 * [@soberbanda](https://wordpress.org/support/users/soberbanda/) It seems like 
   you said, need to used wp query for index page maybe ?
 * So I changed the loop to wp query
 *     ```
       <?php
                     $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
                     $query = new WP_Query( array( 'post_type' => 'post', 'post_status' => 'publish', 'paged'=> $paged) );
   
                     ?>
                   <?php while($query->have_posts()) : $query->the_post(); ?>
       ```
   
 * The duplicate only on the next pagination page, after changed with wp query, 
   no more duplicated post. So any Idea where it went wrong ?
    Or wordpress need
   to use wp query in index.php ?

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘My WordPress Loop strange’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 6 replies
 * 2 participants
 * Last reply from: [lucius100](https://wordpress.org/support/users/lucius100/)
 * Last activity: [4 years, 8 months ago](https://wordpress.org/support/topic/my-wordpress-loop-strange/#post-14933242)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
