Title: get_posts arguments
Last modified: August 18, 2016

---

# get_posts arguments

 *  [jimhere](https://wordpress.org/support/users/jimhere/)
 * (@jimhere)
 * [19 years, 6 months ago](https://wordpress.org/support/topic/get_posts-arguments/)
 * I’m trying to get WP to display infro from the_excerpt is a page, but I can’t
   make get_posts obey ‘category=5’ to make it only show posts from my “photos” 
   category. It WILL work with ‘numberposts=25’, but not ‘category’, as described
   in [http://codex.wordpress.org/Template_Tags/get_posts](http://codex.wordpress.org/Template_Tags/get_posts).
   Why?
 * `<?php
    $posts = get_posts('numberposts=25'); foreach($posts as $post) : setup_postdata(
   $post); ?> <div id="post"> <div class="thumb"> <a href="<?php the_permalink();?
   >" title=""><?php the_excerpt(); ?></a> <h3><a href="<?php the_permalink() ?>"
   ><?php the_title(); ?></a></h3> <h4><?php the_time('M jS, Y') ?></h4> </div> 
   </div> <?php endforeach; ?>

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

 *  Thread Starter [jimhere](https://wordpress.org/support/users/jimhere/)
 * (@jimhere)
 * [19 years, 6 months ago](https://wordpress.org/support/topic/get_posts-arguments/#post-478257)
 * Is it the “foreach” thing?
 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [19 years, 6 months ago](https://wordpress.org/support/topic/get_posts-arguments/#post-478280)
 * I can’t say for sure, but it’s *possible* a conflict with WordPress’ global $
   posts object is being exhibited here. Try changing your code to something like:
 * `$my_posts = get_posts('numberposts=25&category=5');
    foreach($my_posts as $post):
 * Note I added in the `category` argument, assuming you just left it off here (
   you were using it, correct?).
 *  Thread Starter [jimhere](https://wordpress.org/support/users/jimhere/)
 * (@jimhere)
 * [19 years, 6 months ago](https://wordpress.org/support/topic/get_posts-arguments/#post-478294)
 * That totally worked — thanks.
    Was it a php syntax thing? I’m not that good with
   the deeper guts of WP…

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

The topic ‘get_posts arguments’ is closed to new replies.

## Tags

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

 * 3 replies
 * 2 participants
 * Last reply from: [jimhere](https://wordpress.org/support/users/jimhere/)
 * Last activity: [19 years, 6 months ago](https://wordpress.org/support/topic/get_posts-arguments/#post-478294)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
