Title: Pages &#8211; using the loop and query_posts
Last modified: August 18, 2016

---

# Pages – using the loop and query_posts

 *  [ericmcgregor](https://wordpress.org/support/users/ericmcgregor/)
 * (@ericmcgregor)
 * [20 years ago](https://wordpress.org/support/topic/pages-using-the-loop-and-query_posts/)
 * Hi.
 * I have created a page called ‘articles’ (id=2).
 * On this page I would like to have the page title and body, I would also like 
   to query all posts from a particular catagory, AND I need to run list_pages()
   and have it list the ‘articles’ page as being current. whew!
 * If I use query_posts() to try and pull in all posts from my category, it breaks
   list_pages() knowing that this is the current page and applying the current_page_item
   class the the li tag.
 * I have done some digging and it turns out this is because apparently query_posts()
   resets the query object? (whatever THAT means) 😉 Essentially, I believe that
   query_posts is doing something to list_pages preventing it from knowing that 
   the page its on is the current one.
 * Any help on how to pull specifc post catagories into a page would really help.
   Thanks!

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

 *  Thread Starter [ericmcgregor](https://wordpress.org/support/users/ericmcgregor/)
 * (@ericmcgregor)
 * [20 years ago](https://wordpress.org/support/topic/pages-using-the-loop-and-query_posts/#post-400100)
 * Ok, I figured it out!
 * On this page: [http://codex.wordpress.org/The_Loop](http://codex.wordpress.org/The_Loop)
   
   Scroll down, you’ll see this:
 * <?php $my_query = new WP_Query(‘category_name=special_cat&showposts=10’); ?>
 * <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <!– Do special_cat
   stuff… –> <?php endwhile; ?>
 * <?php rewind_posts(); ?>
 * What you want to do is build your own query, then reweind posts to reset the 
   query object so that list_pages doesn’t break.
 *  [davidchait](https://wordpress.org/support/users/davidchait/)
 * (@davidchait)
 * [20 years ago](https://wordpress.org/support/topic/pages-using-the-loop-and-query_posts/#post-400179)
 * actually, another method is to simply ‘store’ into variables the bits about the
   initial query (such as the categories) before starting your custom query. Then
   refer to that anywhere later on the page.
 * -d
 *  Thread Starter [ericmcgregor](https://wordpress.org/support/users/ericmcgregor/)
 * (@ericmcgregor)
 * [20 years ago](https://wordpress.org/support/topic/pages-using-the-loop-and-query_posts/#post-400202)
 * Thanks david. I’m not sure what that means though. I’m not a programmer, and 
   so my level of understanding is very basic. Maybe you could provide an example?

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

The topic ‘Pages – using the loop and query_posts’ is closed to new replies.

## Tags

 * [breaks](https://wordpress.org/support/topic-tag/breaks/)
 * [custom](https://wordpress.org/support/topic-tag/custom/)
 * [list_pages](https://wordpress.org/support/topic-tag/list_pages/)
 * [posts](https://wordpress.org/support/topic-tag/posts/)
 * [query](https://wordpress.org/support/topic-tag/query/)
 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)
 * [templates](https://wordpress.org/support/topic-tag/templates/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [ericmcgregor](https://wordpress.org/support/users/ericmcgregor/)
 * Last activity: [20 years ago](https://wordpress.org/support/topic/pages-using-the-loop-and-query_posts/#post-400202)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
