• Hi.
    All i want to do is exclude posts that belongs to one category from blog index (index.php).
    So here is what I did, and was sure it will work:

    <?php global $query_string; ?>
    <?php query_posts( $query_string . '&cat=-X' );?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    .
    .
    .
    <?php endwhile; endif; ?>

    But posts from category number X are still displayed in blog index. The only working solution was to use:
    <?php if (in_category('8')) continue; ?>
    but it mess with posts number (counts hidden post to global posts number on page) and it is not solution I’m seraching for.

    Please – show me, where my thinking is wrong.
    Thanks in advice
    Martin.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter CyberSpy

    (@cyberspy)

    What is even stranger, if i use this code on clean WP installation, it works ok.
    Also have found, that:

    <?php query_posts( '&cat=-X' );?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    .
    <?php endwhile; endif; ?>'

    Does what it should, but paging stoped to work, so as a workaround:

    <?php $args = array('cat' => -8, 'paged' => $paged ); ?>
    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts($args); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    .
    <?php endwhile; endif; ?>'

    did what it was supposed to do – removed posts from category ID=8 and restored index pagination.
    The question is, beside the fact, that solution, maybe not very elegant, why does the first method not work?
    How could I check, where my new query is overriten by oryginal (which function to hack in?)?

    I had the same problem and your fix saved me. The original $query_string worked with my testing environment, but then on the live site it stopped working.

    I wanted to add that in the first line, I have multiple categories removed:

    <?php $args = array('cat' => '-1,-2,-3', 'paged' => $paged ); ?>

    I don’t know why it would work in one environment but not the other, but thanks again for the workaround.

    Thread Starter CyberSpy

    (@cyberspy)

    This problem have happened on sites, that were ok before. I wonder if this anything to do with number of posts in this and other categories, because on clean wp, where I add only posts to check if pagination on that page works ok, it does, but while other posts are beeing submited, it might mess around with something.
    Maybe it is another bug corresponding to one, that I have found in query.php before, but as for now, I need to test ir mote before submiting to bugtraq.

    Hi,

    Maybe this

    <?php query_posts($query_string.’page=ID&posts_per_page=15′); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    will work with WP-PageNavi plugin

    gabf7

    (@gabf7)

    First, thank you so very much CyberSpy for this workaround, been going crazy with this issue.

    But like you i’d really like to know why this started happening in the first place…. i’ve looked all over and really, but really don’t see what could possibly be causing such a thing.

    anyways, thanks again and let’s hope someone figures this out somehow.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘query_posts( $query_string . '&cat=-XX' ) does not work as it supposed to do’ is closed to new replies.