WordPress Pagination not working, any ideas?

Hello @lukepnnngtn and welcome! Prepare yourself for reading.

Since you’re working on the index.php file we need to consider what’s said in the docs under Removing query_posts from the Main Loop in the Pagination Codex (link):

For example, let’s say your theme queries the main loop like this on
your home page (index.php) and category pages (category.php) and the
pagination is not working…

What you need to do is to remove the WP_Query() from the index.php file and make an action in the function.php. It’s described beat by beat in the link but I will paste it here too:

function my_post_queries( $query ) {
  // do not alter the query on wp-admin pages and only alter it if it's the main query
  if (!is_admin() && $query->is_main_query()){

    // alter the query for the home and category pages 

    if(is_home()){
      $query->set('posts_per_page', 3);
    }

    if(is_category()){
      $query->set('posts_per_page', 3);
    }

  }
}
add_action( 'pre_get_posts', 'my_post_queries' );

After that we need to go back to the index.php file. At this point it should look something like this:

while ( have_posts() ) :
    the_post();

    ...

endwhile;

global $wp_query;

echo paginate_links( array(
    'base' => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
    'total'         => $wp_query->max_num_pages,
    'current'       => max( 1, get_query_var('paged') ),
    'format'        => '?paged=%#%',
    'show_all'      => false,
    'type'          => 'plain',
    'end_size'      => 2,
    'mid_size'      => 1,
    'prev_next'     => true,
    'prev_text'     => sprintf( '<i></i> %1$s', __( 'Newer Posts', 'text-domain' ) ),
    'next_text'     => sprintf( '%1$s <i></i>', __( 'Older Posts', 'text-domain' ) ),
    'add_args'      => false,
    'add_fragment'  => '',
) );

I looked into your code some more and I also suggest reading WordPress’ documentation on (get_query_var()):

For getting the current pagination number on a static front page (Page
template) you have to use the ‘page’ query variable…

After some more research, I found this answer (link) on another WP related question that reads:

  • paged -> Used on the homepage, blogpage, archive pages and pages to calculate pagination. 1st page is 0 and from there the number corresponds to the page number
  • page -> Use on a static front page and single pages for pagination. Pagination on these pages works the same, a static front page is treated as a single page on pagination.

This is straight from the docs (link):

If the pagination is broken on a static front page you have to add the
“paged” parameter this way…

So what you did here is great:

if ( get_query_var('paged') ) {
    $paged = get_query_var('paged');
}
elseif ( get_query_var('page') ) {
    $paged = get_query_var('page');
}
else {
    $paged = 1;
}

Your code was working just fine when I used it on a static page with a custom template up until the moment I made it Homepage, then you need to use the $paged variable for the current argument in the paginate_links() call, like this:

paginate_links( array(
    ...
    'current'       => max( 1, $paged ),
    ...
) );

I still can’t ask questions in the comments so I hope I was helpful. Good luck!