Title: get_posts doesn&#039;t work with numberposts &amp; category
Last modified: August 19, 2016

---

# get_posts doesn't work with numberposts & category

 *  [withinsight](https://wordpress.org/support/users/withinsight/)
 * (@withinsight)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/get_posts-doesnt-work-with-numberposts-category/)
 * I’ve never had much luck using showposts, posts_per_page, or numberposts in any
   theme work, but this one is isolated and should absolutely work.
 * I’ve created a new php file in a subfolder in my theme, and called:
 * require(‘wp-blog-header.php’);
 * in order to make sure I can use all the regular WordPress functions. I was having
   this same issue in regular template files, but I wanted to remove all possibility
   of conflict with the main WP query, or any other other queries.
 * I have 2 calls to get_posts. When ‘category_name’ (or ‘category’) is removed 
   from the array, numberposts works:
 * get_posts(array(‘numberposts’ => 1));
 * As soon as I add in a category:
 * get_posts(array(‘numberposts’ => 1, ‘category_name’ => ‘sample’));
 * get_posts returns all posts in this category. I’ve tried using the cat id rather
   than the slug, with ‘category’, to no avail. I’ve read this trac, and haven’t
   come across anything that looks like a solution:
 * [http://core.trac.wordpress.org/ticket/7326](http://core.trac.wordpress.org/ticket/7326)
 * I’ve always reverted to working around this WordPress issue by using a PHP break
   to kill my loop, but it seems like this should work. Any ideas?

The topic ‘get_posts doesn't work with numberposts & category’ is closed to new 
replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [withinsight](https://wordpress.org/support/users/withinsight/)
 * Last activity: [15 years, 3 months ago](https://wordpress.org/support/topic/get_posts-doesnt-work-with-numberposts-category/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
