0

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();
?>
1

try:

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

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

  • 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
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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