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?