'Why displaying only one category posts on index page breaks pagination?

I am using the query_posts('cat=3'); to display posts from the desired category, and it works as expected. However the index.php page can use the function the_posts_pagination( array(args)); to display below the pages buttons with numbers, previous and next buttons. When i set the query, the paginaton stops working. The index page displays only the first 4 posts(this is my global WP setting), however when i click on button 2 or button next it goes to https://mywebaddress/page/2/, but the four blog posts are the ones from my first page and also button 2 from pagination is not activated, still the number one is activated. When i press the NEXT button it does noting at all but reloads the first page again. The wp_reset_query(); also didn't help, yes i can move through the pages, but still the first four posts from my category are displayed, despite i am on 7 or 8 page for example. I have tied also using a query object, this didn't help too, the result is absolutely the same. Here is the original code with only two commands added by me - the query and the reset, i cannot figure out what causes the problem and how to resolve it.

<?php get_header(); newscard_layout_primary();?>
    <main id="main" class="site-main">

    <?php if ( is_home() && !is_front_page() ) {

        if ( ($newscard_settings['newscard_banner_display'] === 'front-blog' && ($newscard_settings['newscard_banner_slider_posts_hide'] === 0 || $newscard_settings['newscard_banner_featured_posts_1_hide'] === 0 || $newscard_settings['newscard_banner_featured_posts_2_hide'] === 0)) || $newscard_settings['newscard_header_featured_posts_hide'] === 0 ) { ?>

            <h2 class="stories-title"><?php echo get_the_title(get_option('page_for_posts')); ?> </h2>

        <?php } else { ?>

            <header class="page-header">
                <h2 class="page-title"><?php echo get_the_title(get_option('page_for_posts')); ?> </h2>
            </header><!-- .page-header -->

        <?php }

    } query_posts('cat=3'); //this is my desired category ID
    
        if ( have_posts() ) : ?>
        <div class="row gutter-parent-14 post-wrap">
            <?php 
            
             while ( have_posts() ) :
            
                the_post();
                
                get_template_part( 'template-parts/content', get_post_format() );

            endwhile; wp_reset_query(); ?> //here is the query reset
        </div><!-- .row .gutter-parent-14 .post-wrap -->

        <?php the_posts_pagination( array(
            'prev_text' => __( 'Предишен', 'newscard' ),
            'next_text' => __( 'Следващ', 'newscard' ),
            )
        );

    else :

        get_template_part( 'template-parts/content', 'none' );

    endif;
        
    ?>

    </main><!-- #main -->
</div><!-- #primary -->


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source