Pagination is not working in custom post type

Don’t need to start with a new Query in archive.php loop

Only need to create a different loop file for the custom taxonomy and default loop post

See here for more details Filtering a custom post type by custom taxonomy in archive template

example I have taxonomy “service”

archive.php file


<?php 
get_header();

if (is_post_type_archive('service') || is_tax('services-category') || is_tax('services-tags')){
    get_template_part('my-loop-service'); // Get Loop for Taxonomy service
} else {
   get_template_part('my-loop-post'); // Default Loop for Post

}

    // Navigation
    echo '<div id="my-navigation">';
    the_posts_pagination( array(
        'mid_size' => 2,
        'prev_text' => __( 'Prev', 'text-domain' ),
        'next_text' => __( 'Next', 'text-domain' ),
    ));
    echo '</div>';

get_footer(); 
?>