Site icon Hip-Hop Website Design and Development

What does setup_postdata ($post ) do?

The codex defines it as ‘Set up global post data. Helps to format custom query results for using Template tags.’ I don’t really understand this.

Here is a code example :

global $post;
$args = array( 'numberposts' => -1);
$posts = get_posts($args);
foreach( $posts as $post) : setup_postdata($post);
echo $post->ID;
endforeach; 

Please can you explain?