Site icon Hip-Hop Website Design and Development

Pagination in plugin with custom post type

I have several custom post types (created through CPT UI plugin). I want to display posts from these post types on my page, for example “News”. I’ve created a page and inserted in it shortcode [show_posts post_type="novyny"]. I’ve got a plugin that processes this shortcode

function foo($args){
    $post_type = $args['post_type'];
    $custom_post_type = new WP_Query(
        array(
            'post_type' => $post_type,
            'orderby' => 'date',
            'order' => 'DESC',
            'posts_per_page' => 4
        )
    );

    if( $custom_post_type->have_posts() ) :
        while( $custom_post_type->have_posts() ): $custom_post_type->the_post(); ?>
            <h1><a href="<?php the_permalink(); ?>"><?php the_title() ?></a></h1>
            <p> <?php the_modified_date(); echo ", "; the_modified_time() ?></p>
            <p> <?php the_excerpt() ?></p>
        <?php endwhile;
        the_posts_pagination();
    endif;
    wp_reset_postdata();
}

add_shortcode('show_posts', 'foo');

Posts are displayed, but pagination blog doesn’t appear at the page even if there is more than 4 posts to display. What’s wrong?