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'm trying to exclude a category because I have a post that i have in multiple post. How do I like for example I have a post in the categories lastest news and pictures but I want to exclude latest news and show only the pictures name. I tried using $category = get_the_category(); echo $category[0]->cat_name; but that's no help.

any help is appreciated.

share|improve this question

3 Answers 3

$recentPosts = new WP_Query(); $recentPosts->query('cat=-3'); //-3 makes sure it shows all categories except for ID number 3
        while ($recentPosts->have_posts()) : $recentPosts->the_post(); 

the_title();
the_content();        

endwhile;

Would something like this Work?

share|improve this answer
    
:) no but thanks for trying. –  Jeremy Love Mar 8 '11 at 2:20
up vote 1 down vote accepted

actually I fingered it out this code worked.

<?php
//edit below for categories you want excluded
$exclude = array("Latest News", "Uncategorized");
//how do you want the list separated? just a space is okay
$separator = " | ";
//don't edit below here!
$new_the_category = '';
foreach((get_the_category()) as $category) {
if (!in_array($category->cat_name, $exclude)) {
$new_the_category .= '<a href="'.get_bloginfo(url).'/'.get_option('category_base').'/'.$category->slug.'">'.$category->name.'</a>'.$separator;
}
}
echo substr($new_the_category, 0, strrpos($new_the_category, $separator));
?>  
share|improve this answer

Ok, try this:

<?php
$category = get_term_by( 'name', 'lastest news', 'category' );
$args = array (
    'tax_query' => array (
        array (
            'taxonomy' => 'category',
            'field'    => 'slug',
            'terms'    => $category->slug,
            'operator' => 'NOT IN'
        )
    )
);
query_posts($args);

This example need WP 3.1 to work. See more: Taxonomy parameters.

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.