Title: WP Query exclude category_name
Last modified: August 20, 2016

---

# WP Query exclude category_name

 *  [billbennett](https://wordpress.org/support/users/billbennett/)
 * (@billbennett)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/wp-query-exclude-category_name/)
 * I’ve got two loops.
 * One loop pulls the last four items from a category called “featured” thus:
 * $my_query = new WP_Query(‘category_name=featured&showposts=4’);
 * I’d like to have a second loop which pulls the last 8 items for every category
   EXCEPT featured. I wrote it using the minus sign to remove the unwanted category
   as:
 * $my_query = new WP_Query(‘category_name=-featured&showposts=8’);
 * But that does’t work. Any ideas of a better way of doing this?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/wp-query-exclude-category_name/#post-2117211)
 * turn the category name into a category id first:
    [http://codex.wordpress.org/Function_Reference/get_cat_ID](http://codex.wordpress.org/Function_Reference/get_cat_ID)
 * `$cat_id = get_cat_ID('featured');`
 * then use:
 * `$my_query = new WP_Query('cat=-'.$cat_id.'&showposts=8');`
 * [http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters](http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters)
 *  Thread Starter [billbennett](https://wordpress.org/support/users/billbennett/)
 * (@billbennett)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/wp-query-exclude-category_name/#post-2117397)
 * Thanks. This works.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘WP Query exclude category_name’ is closed to new replies.

## Tags

 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * 2 replies
 * 2 participants
 * Last reply from: [billbennett](https://wordpress.org/support/users/billbennett/)
 * Last activity: [14 years, 11 months ago](https://wordpress.org/support/topic/wp-query-exclude-category_name/#post-2117397)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
