Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

PROBLEM

Hey everyone I have the wp loop to display posts, but I need to exclude category 81. I tried: query_posts('cat=-81'); ?> before the loop but the pagenavi is broken and it doesn't work properly.

CODE

    <?php  if(have_posts()): ?>

                <ol class="list posts">

                <?php
                    $end = array(3,6,9,12,15,18,21,24,27,30,33,36,39,42,45);
                    $i = 0;
                    while (have_posts()) : the_post();
                    $i++;
                    global $post;
                ?>

HEADER

I have this in the begining of the page - maybe it has something to do with it?:

<?php get_header();

global $wp_query;
$curauth = $wp_query->get_queried_object();
?>
share|improve this question

2 Answers 2

up vote 1 down vote accepted

try:

global $query_string;
query_posts( $query_string . '&cat=-81' );

http://codex.wordpress.org/Function_Reference/query_posts#Preserving_Existing_Query_Parameters

share|improve this answer
    
Awesome, that worked perfectly. Will it be problem to leave the global $wp_query; $curauth = $wp_query->get_queried_object(); along with the new global You posted? Will there be any problems in wp? –  jimilesku Mar 27 '12 at 12:04
    
I would not expect any problems with that. –  Michael Mar 27 '12 at 13:38
    
Cheers, it works fine! –  jimilesku Mar 27 '12 at 14:18

Something like this would work

$cat = ( !empty( $wp_query->get('cat') ) )
    ? wp_query('cat').',-81'
    : '-81';
$wp_query->set(
    'cat',
    $cat
);

But what you really want to be doing is using tax_query and just setting the taxonomy parameter to category.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.