Creating widget – ask for selecting a post in the admin panel

First off, try to work on your code formatting. As it is, it’s rather unreadable and this makes it not only more difficult for us to understand how to help you, but also less scalable and suited for future use. Always try to adhere to the WordPress PHP Coding Standards.

Now, on to the beef of the problem…

To add a new setting to a widget, you have to implement functionality in two class method of the class you already have: form() and update(). In form(), we’re going to display the post dropdown, and in update(), we’re going to save the selected post.

Displaying the dropdown

To display the dropdown, we utilize WP_Query, which creates a query for fetching all posts. We place this code in the form function before actually displaying anything. The code below fetches all (posts_per_page=1) posts from post types post and page (post_type=post,page), ordering them by title (orderby=post_title) ascendingly (order=ASC). The resulting posts are stored in the property $posts_query->posts.

$posts_query = new WP_Query( array(
    'post_type' => array( 'post', 'page' ), // Replace by your posts types for event type 1 and 2
    'posts_per_page' => -1,
    'orderby' => 'post_title',
    'order' => 'ASC'
) );

Next, we display the dropdown in the form() method as well, by simply looping over the posts found.

<p>
    <label for="<?php echo $this->get_field_id( 'post' ); ?>"><?php _e( 'Post' ); ?></label>
    <select name="<?php echo $this->get_field_name( 'post' ); ?>" id="<?php echo $this->get_field_id( 'post' ); ?>" class="widefat">
        <?php foreach ( $posts_query->posts as $post ) : ?>
            <option value="<?php echo $post->ID; ?>" <?php selected( $post->ID, $instance['post'] ); ?>>
                <?php echo $post->post_title; ?>
            </option>
        <?php endforeach; ?>
    </select>
</p>

Try to understand the code above, as you will need it for creating more widget options in the future!

Saving the post selected in the form

Now, we use the update() method to save the selected post when somebody saves the widget. To do so, just one more line is required right before $instance is returned.

$instance['post'] = $new_instance['post'];

This adds the new post to the instance array that will be used to update the instance.

This should be enough..

..to help you on your way. Good luck with displaying the post in the widget!