Custom post type pagination not working in index.php file

You registered your post type correctly, the problem is a common pitfall many new WordPress developers fall into, you created a second new query to change the posts WP displays, rather than modifying the original.

Why It’s Broken

A lot of people don’t understand the main query and think that if they want to change what gets displayed on a page, that they should create a new query and tell it what they want using WP_Query/get_posts/query_posts. This might be to change the number of posts or to pull in different posts, or filter to a category or tag, etc.

AKA this part of your code:

    $news_query = new WP_Query( $args ); // Create a new query
    if ( $news_query->have_posts() ) : ?>
        <?php while ( $news_query->have_posts() ) : $news_query->the_post(); ?>         

But this is a trap! You’ve just doubled the amount of work WordPress needs to do slowing things down, and the main query is still there loading the same posts it did before you made the change.

So if you ignore that main query WP generates, and don’t use a standard main loop but create your own, you now have a problem, the pagination is broken and it always shows the first page of results. That’s what this is trying to patch over:

    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; // Get the current page number
....
        'paged' => $paged // Use the current page number
...
            <?php echo paginate_links( array( 'total' => $news_query->max_num_pages ) ); ?>

This is a lot of messy complicated code to fix things. Except if the homepage only has 3 pages of posts, but your new custom query has 4, what happens when you try to load page 4? It 404’s because there is no page 4.

How Do I Fix It?

First get rid of the second new custom query in your template. Your loop should look more like this:

<div class="row">
    <?php 
    if ( have_posts() ) :
        while ( have_posts() ) : the_post(); ?>
            
           MY HTML CONTENT 

        <?php endwhile; ?>
        <div class="pagination">
            <?php echo paginate_links(); ?>
        </div>
    <?php endif; ?>
</div>

Notice the loop has no WP_Query and it uses have_posts/the_post without any extra stuff. There’s also no complicated pagination code.

Changing What Gets Shown On The Homepage Correctly/Safely

To change what gets shown in the main query, don’t create a new query, use pre_get_posts, for example this filter changes the main query on the homepage so it has a maximum of 3 posts per page:

function only_3_posts_on_homepage( \WP_Query $query ) {
    if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'posts_per_page', 3 );
    }
}
add_action( 'pre_get_posts', 'only_3_posts_on_homepage' );

Now on all pages where is_home() is true the number of posts per page is changed to 3. You can use $query->set( to change any of the other options WP_Query accepts, such as the post_type or order.

This method is both faster, safer, and easier to type.

Further reading:

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)