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.

I am trying to use ids to control the structure of the output of my categories. I need to exclude a category that is part of the parent category that is being queried.

What I am trying is :

<?php $the_query = new WP_Query('cat=14$cat=-45&showposts=20');
        $permalink = get_permalink( $post_id );
        while ($the_query->have_posts()) : $the_query->the_post();?>    
            <li>
            <a href="<?php the_permalink() ?>" rel="bookmark" class="postTitleLink">
            <?php the_title(); ?></a>
            </li>
        <?php wp_reset_query(); ?><?php endwhile; ?>

What would be the correct way to show everything in category id 14, except for category 45? I want to treat 45 differently and show all of its sub categories in a different way. To try and help describe what I want :

#12
- #14
- #14
- #14
 -- #45
  --- #50
   ---- #60
  --- #51
- #14

instead of cat=- should I be using conditional statements instead .. !in_category ?

Thanks for any help!

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

First you should move wp_reset_query(); outside of the loop instead of resetting the query every post of the loop.

And as for your query you can use category__not_in

$args = array(
    'cat' =>  14,
    'category__not_in' => array('45'),
    'posts_per_page' => 20
);

$the_query = new WP_Query($args);
while ($the_query->have_posts()) : $the_query->the_post();?>    
            <li>
            <a href="<?php the_permalink() ?>" rel="bookmark" class="postTitleLink">
            <?php the_title(); ?></a>
            </li>
<?php endwhile; ?>
<?php wp_reset_query(); ?>

this will exclude all posts of category 45.

share|improve this answer
add comment

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.