I have a wordpress page that has a series of listings and a searchbox at the top. The search allows the user to filter posts by creating a custom WP_Query object based on what they selected. I am wondering if there is a way I can have this be paginated so that there aren't hundreds of results displaying on the page.
Basically I have an if statement to check if the form is submitted which then populates the selected fields into an array and passes it to the meta_query
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
if(isset($_POST['submit'])){
$the_query = new WP_Query(array(
'post_type' => 'business',
'post_status' => 'publish',
'taxonomy' => 'business-type',
'business-type' => 'attraction',
'posts_per_page' => 15,
'orderby' => 'title',
'order' => 'ASC',
'meta_query' => $arrays,
'paged' => $paged
));
}else{
$the_query = new WP_Query(array(
'post_type' => 'business',
'post_status' => 'publish',
'taxonomy' => 'business-type',
'business-type' => 'attraction',
'posts_per_page' => 15,
'orderby' => 'title',
'order' => 'ASC',
'paged' => $paged
));
The I loop through the query using while ( $the_query->have_posts() ) : $the_query->the_post();
and after endwhile; I have my pagination
if($the_query->max_num_pages>1){?>
<div class="pagination">
<?php
if ($paged > 1) { ?>
<a href="<?php echo '?paged=' . ($paged -1); //prev link ?>"><</a>
<?php }
for($i=1;$i<=$the_query->max_num_pages;$i++){
if($paged==$i){?>
<span class="current"><?php echo $i; ?></span>
<?php }else{?>
<a href="<?php echo '?paged=' . $i; ?>" class="inactive"><?php echo $i;?></a>
<?php
}
}
if($paged < $the_query->max_num_pages){?>
<a href="<?php echo '?paged=' . ($paged + 1); //next link ?>">></a>
<?php } ?>
</div>