Title: Need help using get_posts
Last modified: August 19, 2016

---

# Need help using get_posts

 *  Resolved [martinfamily2005](https://wordpress.org/support/users/martinfamily2005/)
 * (@martinfamily2005)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/need-help-using-get_posts/)
 * I am trying to pull only one specific post using get_posts, but I can not seem
   to get that to work. What I have now works, but it pulls the most recent post.
   I want to pull a SPECIFIC post, by id or some other similar way. Can you please
   help me out?
 * Here is the code I am using:
 *     ```
       <div class="sponsor">
       <?php
        			global $post;
       			$myposts = get_posts('category=9&numberposts=1');
        			foreach($myposts as $post) :
          			setup_postdata($post);
        			?>
   
       				<div class="sponsortext">
   
       					<?php  the_excerpt(); ?>
       				</div>
       				<div class="break"></div>
   
       			<?php endforeach; ?>
       </div>
       ```
   

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

 *  [Rev. Voodoo](https://wordpress.org/support/users/rvoodoo/)
 * (@rvoodoo)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/need-help-using-get_posts/#post-1854894)
 *     ```
       $args = array(
             'post__in' => array(22),
       );
       ```
   
 * then
 *     ```
       $myposts = get_posts($args);
       ```
   
 * where 22 is the post ID
 *  Thread Starter [martinfamily2005](https://wordpress.org/support/users/martinfamily2005/)
 * (@martinfamily2005)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/need-help-using-get_posts/#post-1854897)
 * Hmmm. that seems to have had no effect.
 *  [Rev. Voodoo](https://wordpress.org/support/users/rvoodoo/)
 * (@rvoodoo)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/need-help-using-get_posts/#post-1854901)
 * really? whats your total code now?
 *  Thread Starter [martinfamily2005](https://wordpress.org/support/users/martinfamily2005/)
 * (@martinfamily2005)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/need-help-using-get_posts/#post-1854926)
 *     ```
       <div class="sponsor">
       <?php
   
        			$args = array(
             'post__in' => array(688),
       );
                               global $post;
       			$myposts = get_posts('category=9&numberposts=1');
        			foreach($myposts as $post) :
          			setup_postdata($post);
        			?>
   
       				<div class="sponsortext">
   
       					<?php  the_excerpt(); ?>
       				</div>
       				<div class="break"></div>
   
       			<?php endforeach; ?>
       </div>
       ```
   
 *  [Rev. Voodoo](https://wordpress.org/support/users/rvoodoo/)
 * (@rvoodoo)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/need-help-using-get_posts/#post-1854928)
 * you don’t actually call the args….
 *     ```
       $myposts = get_posts('category=9&numberposts=1');
       ```
   
 * should now be
 *     ```
       $myposts = get_posts($args);
       ```
   
 *  Thread Starter [martinfamily2005](https://wordpress.org/support/users/martinfamily2005/)
 * (@martinfamily2005)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/need-help-using-get_posts/#post-1854944)
 * duh. I will change it and let you know what happens. thanks!
 *  Thread Starter [martinfamily2005](https://wordpress.org/support/users/martinfamily2005/)
 * (@martinfamily2005)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/need-help-using-get_posts/#post-1854960)
 * That is the ticket! Thanks!
 *  [Rev. Voodoo](https://wordpress.org/support/users/rvoodoo/)
 * (@rvoodoo)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/need-help-using-get_posts/#post-1854975)
 * nice! glad it worked

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

The topic ‘Need help using get_posts’ 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/)
 * 8 replies
 * 2 participants
 * Last reply from: [Rev. Voodoo](https://wordpress.org/support/users/rvoodoo/)
 * Last activity: [15 years, 4 months ago](https://wordpress.org/support/topic/need-help-using-get_posts/#post-1854975)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
