Title: get_posts loop outside &#8216;the loop&#8217; don&#8217;t see post objects
Last modified: August 18, 2016

---

# get_posts loop outside ‘the loop’ don’t see post objects

 *  [asknight](https://wordpress.org/support/users/asknight/)
 * (@asknight)
 * [20 years, 8 months ago](https://wordpress.org/support/topic/get_posts-loop-outside-the-loop-dont-see-post-objects/)
 * Scenario:
    -in the template but prior to the loop:: $extraposts = get_posts(‘
   yadda1=x&yadda2=y…’); print_r($extraposts); -plenty of posts are there if $extraposts:
   foreach $extraposts as $post : start_wp(); …<?=some_core_or_plugin_function_doesn’t_matter();?
   >… . . . endfor; endif; function some_core_or_plugin_function_doesn’t_matter(){
   print_r($post); -NOTHING print_r($extraposts); -NOTHING } I don’t get it. but
   this did work under 1.2

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

 *  Thread Starter [asknight](https://wordpress.org/support/users/asknight/)
 * (@asknight)
 * [20 years, 8 months ago](https://wordpress.org/support/topic/get_posts-loop-outside-the-loop-dont-see-post-objects/#post-267363)
 * b.t.w. forgot to mention:
    global $post, $extraposts; should have been included
   in the example above.
 *  [TechGnome](https://wordpress.org/support/users/techgnome/)
 * (@techgnome)
 * [20 years, 8 months ago](https://wordpress.org/support/topic/get_posts-loop-outside-the-loop-dont-see-post-objects/#post-267368)
 * Soooo, you’re problem is what exactly?
 * Are you expecting $post and $extraposts to be something at the end there? Because
   I wouldn’t expect them to be.
 * $post won’t be anything because it hasn’t been set yet. And for $extraposts, 
   you’ve already looped through them, so you would be at the end position….
 * -tg
 *  Thread Starter [asknight](https://wordpress.org/support/users/asknight/)
 * (@asknight)
 * [20 years, 8 months ago](https://wordpress.org/support/topic/get_posts-loop-outside-the-loop-dont-see-post-objects/#post-267387)
 * Nooooo, the function is being called however many times in the foreach loop. 
   I’d expect both $post and $extraposts to be happening.

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

The topic ‘get_posts loop outside ‘the loop’ don’t see post objects’ is closed to
new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [asknight](https://wordpress.org/support/users/asknight/)
 * Last activity: [20 years, 8 months ago](https://wordpress.org/support/topic/get_posts-loop-outside-the-loop-dont-see-post-objects/#post-267387)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
