Support » How-To and Troubleshooting » [Resolved] Problem with “php query_posts” please help..

[Resolved] 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 (as it sits now, the code is in the template so you can see how it is not working properly…


Viewing 5 replies - 1 through 5 (of 5 total)
  • <?php query_posts('cat=-7'); ?>
    Change that one line code to the following.

    <?php $wp_query->set( 'cat', '-7' ); ?>
    <?php query_posts( '' ); ?>



    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?

    Did you ever find a fix for this problem? I have the same.

    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

    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?

    Brick Home

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] Problem with “php query_posts” please help..’ is closed to new replies.
Skip to toolbar