Display Custom Post Type in a Widget

Show custom post type content in a widget area.

<?php
function custom_post_type_widget() {
    if (is_active_sidebar('custom_post_type_widget_area')) {
        dynamic_sidebar('custom_post_type_widget_area');
    }
}
add_action('widgets_init', function() {
    register_sidebar(array(
        'name'          => 'Custom Post Type Widget Area',
        'id'            => 'custom_post_type_widget_area',
        'before_widget' => '<div class="custom-post-type-widget">',
        'after_widget'  => '</div>',
        'before_title'  => '<h2>',
        'after_title'   => '</h2>',
    ));
});

Post Comment