Title: global $post and get_posts( )
Last modified: August 20, 2016

---

# global $post and get_posts( )

 *  [sacher](https://wordpress.org/support/users/sacher/)
 * (@sacher)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/global-post-and-get_posts/)
 * Hi,
    I’m just curious about something that maybe has a obvious answer but I cannot
   find it.
 * Why do you use **global $post;** with **get_posts( );**, like in the example 
   bellow. Is it mandatory?
 *     ```
       <?php
       global $post;
       $args = array( 'numberposts' => 5, 'offset'=> 1, 'category' => 1 );
       $myposts = get_posts( $args );
       foreach( $myposts as $post ) :	setup_postdata($post); ?>
       	<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
       <?php endforeach; ?>
       ```
   
 * Thank you,
    Sacher

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/global-post-and-get_posts/#post-2896421)
 * where is that example coming from?
 * can you post a link to that source?
 * afaik, `global $post;` is not needed in that example.
 *  Thread Starter [sacher](https://wordpress.org/support/users/sacher/)
 * (@sacher)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/global-post-and-get_posts/#post-2896439)
 * Hi,
    Thanks for your reply. There are plentyy of example in the WordPress codex
   [http://codex.wordpress.org/Template_Tags/get_posts](http://codex.wordpress.org/Template_Tags/get_posts)
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/global-post-and-get_posts/#post-2896555)
 * using `global $post;` might make sense it this example ‘Reset after Postlists
   with offset’ **if **the code is used in a different template than the main template,
   for instance in the sidebar, or in a function.

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

The topic ‘global $post and get_posts( )’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [Michael](https://wordpress.org/support/users/alchymyth/)
 * Last activity: [13 years, 10 months ago](https://wordpress.org/support/topic/global-post-and-get_posts/#post-2896555)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
