Title: Problem with &#8220;php query_posts&#8221; please help..
Last modified: August 18, 2016

---

# Problem with “php query_posts” please help..

 *  Resolved [altacivil](https://wordpress.org/support/users/altacivil/)
 * (@altacivil)
 * [20 years, 6 months ago](https://wordpress.org/support/topic/problem-with-php-query_posts-please-help/)
 * I have my WP set up so that it does not show certain posts (namely those within
   category 7). I am using
    “<?php query_posts(‘cat=-7’); ?>” as perscribed within
   the codex. This technique works excellent, there is just one small problem. When
   I input this into my template before “the loop” (even if I put it immediately
   below the code that obtains the headder) my “previous” and “next posts” links
   fail to work properly.
 * By fail to work properly I mean they show up like they are supposed to, but the
   posts are the same on the page. I click on “previous posts” link and the page
   changes (the URL changes), but the same posts as are on the main page show up.
   When I remove the “<?php query_posts(‘cat=-7’); ?>” code from my template, the
   previous and next posts links beging to work properly.
 * Anyone know how I can use the query_posts code and get the previous and next 
   posts links to work properly?
 * Here is my page… [http://gpetzold.swifthost.net](http://gpetzold.swifthost.net)(
   as it sits now, the code is in the template so you can see how it is not working
   properly…
 * Thanks!!

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

 *  [Joshua Sigar](https://wordpress.org/support/users/alphaoide/)
 * (@alphaoide)
 * [20 years, 6 months ago](https://wordpress.org/support/topic/problem-with-php-query_posts-please-help/#post-279689)
 * `<?php query_posts('cat=-7'); ?>`
    Change that one line code to the following.
 * `<?php $wp_query->set( 'cat', '-7' ); ?>
    <?php query_posts( '' ); ?>
 *  Thread Starter [altacivil](https://wordpress.org/support/users/altacivil/)
 * (@altacivil)
 * [20 years, 6 months ago](https://wordpress.org/support/topic/problem-with-php-query_posts-please-help/#post-279725)
 * A big thanks to alpaoide!
 * That worked great for the case where i have it set to “set(‘cat’, ‘-7’)” but 
   when I want to display ONLY the posts in category 7 (on a different page in my
   site) ie. “set(‘cat’, ‘7’)” i get an error 404 page when I try to view the “previous
   posts” page.
 * Any ideas?
 *  [dumpling](https://wordpress.org/support/users/dumpling/)
 * (@dumpling)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/problem-with-php-query_posts-please-help/#post-279977)
 * Did you ever find a fix for this problem? I have the same.
 *  [dbasulto](https://wordpress.org/support/users/dbasulto/)
 * (@dbasulto)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/problem-with-php-query_posts-please-help/#post-279984)
 * i have the same issue, with 1.5.2. I’m going to upgrade to 2.0 soon, i wonder
   if the problem still exists in 2.0, or if there’s another way to do it in 2.0
 *  [Seaborn](https://wordpress.org/support/users/joyhog/)
 * (@joyhog)
 * [19 years, 10 months ago](https://wordpress.org/support/topic/problem-with-php-query_posts-please-help/#post-280009)
 * Im on the latest version and I also have the same problem.
    This is what I am
   using
 * <?php query_posts(‘cat=-0’); //gets all posts
    load_template( TEMPLATEPATH . ‘/
   index.php’); //loads index ?>
 * any thoughts?
 * [http://www.joyhog.com](http://www.joyhog.com)

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

The topic ‘Problem with “php query_posts” please help..’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 5 participants
 * Last reply from: [Seaborn](https://wordpress.org/support/users/joyhog/)
 * Last activity: [19 years, 10 months ago](https://wordpress.org/support/topic/problem-with-php-query_posts-please-help/#post-280009)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
