WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
$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(); 



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.

//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:

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

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

share|improve this answer

Your Answer


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.