Title: query_posts and navigation
Last modified: August 19, 2016

---

# query_posts and navigation

 *  [raimy](https://wordpress.org/support/users/raimy/)
 * (@raimy)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/query_posts-and-navigation/)
 * I want to set my index page to show only posts from a certain category which 
   I was able to satisfactorily accomplish using the query_posts option.
 * The problem is that when I click on the next or previous post links it doesn’t
   take me to the next page…just keeps looping me back to the first set of posts
   viewed.
 * Anyone know a fix for this?

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

 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/query_posts-and-navigation/#post-1277817)
 * I think this is because you’ve used this format..
 *     ```
       query_posts( 'cat=3' );
       ```
   
 * Although this would be correct for selecting all posts in category 3, it doesn’t
   account for any cases when your file (index.php or whatever it be, the same applies
   for other files) is being passed any query vars. This may not be a problem if
   you have several other template files handling those query variables (examples
   would be, author, category, month, week, day and so on..)..
 * So what happens is, when a query variable gets set (a request is sent for one),
   and a file is selected to deal with that particular variable, if you make any
   changes to the query_posts line, you essentially lose all queried parameters…(
   unless you pass these into the query_posts line).
 * In this case the paged query_var is not being passed along into the query.
 * To fix the problem…
 *     ```
       // Sets a variable defined by the paged query var, if it doesn't exist, then we know it's page 1
       $paged = get_query_var('paged') ? get_query_var('paged') : 1;
       query_posts( 'YOURARGS&paged='.$paged );
       ```
   
 * Where “YOURARGS” are you current query arguments/parameters …
 * Hope that helps..
 *  Thread Starter [raimy](https://wordpress.org/support/users/raimy/)
 * (@raimy)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/query_posts-and-navigation/#post-1277819)
 * That’s the ticket!! Thanks for your help and for the explanation. 🙂

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

The topic ‘query_posts and navigation’ is closed to new replies.

## Tags

 * [navigation](https://wordpress.org/support/topic-tag/navigation/)
 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [raimy](https://wordpress.org/support/users/raimy/)
 * Last activity: [16 years, 4 months ago](https://wordpress.org/support/topic/query_posts-and-navigation/#post-1277819)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
