Oct 13, 2010

Exclude Posts by Category Name from Home page in Wordpress

I have created a new category 'Idhar-Udhar', But I don't want to show posts related to this category on home page. I saw "Function Reference/query posts". there is parameter category_name which displays posts from only one category by name. There is no parameter to exclude posts by category_name. I tried -(minus sign) in following way, but not worked.

query_posts('category_name=-Idhar-Udhar');

I tried ! sign also, but no luck.

query_posts('category_name!=Idhar-Udhar');

Finally, I have done this using category ID. See following:


$id = get_cat_id('Idhar-Udhar'); 
$q = "cat=-" . $id;
query_posts($q); 
  if (have_posts()) : while (have_posts()) : the_post();

First get ID using get_cat_id function then using cat parameter with -(minus sign) and category ID to exclude.

Hope, It helps