Title: change query
Last modified: August 19, 2016

---

# change query

 *  Resolved [jaw23](https://wordpress.org/support/users/jaw23/)
 * (@jaw23)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/change-query/)
 * Newbie here.
 * How do I change my query so it includes only one post but excludes an array of
   categories?
 * Here’s what I have but I need to change the category from 3 to a bunch of categories(
   and new ones which have not been created yet) so I figured the easiest way is
   to just exclude the ones I don’t want with an array.
 * <?php $recent = new WP_Query(“cat=3&showposts=1”); while($recent->have_posts()):
   $recent->the_post();?>
 * I found an array but it does not specify showing only one post.
 * Many thanks!

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

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/change-query/#post-1356143)
 * For example, if you do not want categories 7,12,14,15,16 you could use
 * `<?php $recent = new WP_Query("cat='-7,-12,-14,-15,-16'&showposts=1"); while(
   $recent->have_posts()) : $recent->the_post();?>`
 * or
 *     ```
       <?php
       $args = array(
         'category__not_in' => array(7,12,14,15,15),
         'showposts' => 1,
       );
       $recent = new WP_Query($args); while($recent->have_posts()) : $recent->the_post();?>
       ```
   
 *  Thread Starter [jaw23](https://wordpress.org/support/users/jaw23/)
 * (@jaw23)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/change-query/#post-1356351)
 * That’s it!
    Thanks so much!

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

The topic ‘change query’ is closed to new replies.

## Tags

 * [array](https://wordpress.org/support/topic-tag/array/)
 * [exclude categories](https://wordpress.org/support/topic-tag/exclude-categories/)
 * [query](https://wordpress.org/support/topic-tag/query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [jaw23](https://wordpress.org/support/users/jaw23/)
 * Last activity: [16 years, 4 months ago](https://wordpress.org/support/topic/change-query/#post-1356351)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
