Title: Having troubles modifying the loop
Last modified: August 24, 2016

---

# Having troubles modifying the loop

 *  [nebdeschue](https://wordpress.org/support/users/nebdeschue/)
 * (@nebdeschue)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/having-troubles-modifying-the-loop/)
 * Hello all
 * I’ve been trying to modify my loop. On category and tag pages I’d like to have
   to posts listed the following:
 * –> first show all posts for this category that are NOT also listed in category
   X
    –> then show all posts for this category that are also listed in category 
   X
 * I did some reading and managed to achieve that with `query_posts`, but this causes
   problems with the pagination … (and apparently it’s a bad idea to use this method
   anyway)
    I tried `WP_Query` but then it shows all posts, not just the ones for
   this category.
 * Can anyone help me out?
    Thanks in advance

Viewing 1 replies (of 1 total)

 *  [allilevine](https://wordpress.org/support/users/firewatch/)
 * (@firewatch)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/having-troubles-modifying-the-loop/#post-6104078)
 * Hi there. Would you mind posting the code you have so far, using `query_posts`?
   You might be able to use a combination of `pre_get_posts` and Conditional Tags:
    - [https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts#Exclude_categories_on_your_main_page](https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts#Exclude_categories_on_your_main_page)
    - [https://codex.wordpress.org/Conditional_Tags#A_Category_Page](https://codex.wordpress.org/Conditional_Tags#A_Category_Page)

Viewing 1 replies (of 1 total)

The topic ‘Having troubles modifying the loop’ is closed to new replies.

## Tags

 * [loops](https://wordpress.org/support/topic-tag/loops/)
 * [multiple loops](https://wordpress.org/support/topic-tag/multiple-loops/)
 * [pagination](https://wordpress.org/support/topic-tag/pagination/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [allilevine](https://wordpress.org/support/users/firewatch/)
 * Last activity: [11 years, 3 months ago](https://wordpress.org/support/topic/having-troubles-modifying-the-loop/#post-6104078)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
