WordPress: Display all posts in dropdown menu

Do you want to show all your WordPress posts in a dropdown menu? It can come handy to allow your visitors browse through the website quickly. Below is the code for creating a dropdown menu with all the posts in it. You can add the code to any template file such as sidebar.php in your WordPress theme.

<form action="<?php bloginfo('url'); ?>" method="get">
<select name="page_id" id="page_id">
<?php
global $post;
$args = array( 'numberposts' => -1);
$posts = get_posts($args);
foreach( $posts as $post ) : setup_postdata($post); ?>
	<option value="<? echo $post->ID; ?>"><?php the_title(); ?></option>
<?php endforeach; ?>
</select>
<input type="submit" name="submit" value="view" />
</form>

Source: WP Snipp