The problem statement
For some reason when the user does a search the results page (search.php) only show the first page results. The pagination (next and previous links) also believes its on page 1.
The URL structure is https://www.domianname.com/page/1?s=query.
You can change out the number for 2, 3, 4 etc and it won't 404 but it will still show page 1 results.
Is this an issue with the WP_Query or could it be the custom URL structure (/page/1)?
Snippet of the search.php file
<?php
$paged = $page
$loop = new WP_Query(
array(
'posts_per_page' => '20',
'paged' => $paged
)
);
if ( $loop->have_posts() ) { ?>
<div class="results">
<?php while ( $loop->have_posts() ) {
$loop->the_post();
$post_id = $post->ID;
?>
<div class="article">
<h3><a href="<?php the_permalink();?>">the_title(); ?></a></h3>
<!-- A bunch of if conditions depending on post type-->
</div><!--close article-->
<?php } ?>
</div><!--close results-->
<?php
if( get_previous_posts_link() || get_next_posts_link() ) {
?>
<div class="navigation">
<?php
if( get_previous_posts_link() ) {
echo '<span class="newer">'.get_previous_posts_link( "Previous Page", $loop->max_num_pages).'</span>';
};
if( get_next_posts_link() ) {
echo '<span class="older">'.get_next_posts_link( "Next Page", $loop->max_num_pages).'</span>';
};
?>
</div>
<?php } ?>
<?php } else { ?>
<p>There are no results for that search query. Please search again.</p>
<?php } ?>