Title: Help checking multiple categories with get_posts
Last modified: August 19, 2016

---

# Help checking multiple categories with get_posts

 *  [Tim F](https://wordpress.org/support/users/tim-f/)
 * (@tim-f)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/help-checking-multiple-categories-with-get_posts/)
 * Hi all,
 * I am using the following to display the single latest post from a category.
 *     ```
       <?php global $post;
       $args = array( 'numberposts' => 1, 'category' => 7 );
       $myposts = get_posts( $args );
       foreach($myposts as $post) :
       setup_postdata($post);
       ?>
       and so on
       ```
   
 * This works great, but now I want to display the single latest post from several
   categories. I thought I could specify a range of categories like this `$args 
   = array( 'numberposts' => 1, 'category' => 7, 8, 9 );` but when I try it, it 
   only displays the most recent post from the first category number I enter.
 * Is there a way I can specify several categories here?
 * Many thanks!
    Tim

Viewing 1 replies (of 1 total)

 *  Thread Starter [Tim F](https://wordpress.org/support/users/tim-f/)
 * (@tim-f)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/help-checking-multiple-categories-with-get_posts/#post-1872110)
 * Any ideas?
    Sorry, I realised I should probably have posted this in the hacks
   forum.

Viewing 1 replies (of 1 total)

The topic ‘Help checking multiple categories with get_posts’ is closed to new replies.

 * 1 reply
 * 1 participant
 * Last reply from: [Tim F](https://wordpress.org/support/users/tim-f/)
 * Last activity: [15 years, 3 months ago](https://wordpress.org/support/topic/help-checking-multiple-categories-with-get_posts/#post-1872110)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
