I am trying to combine sorting and pagination in Wordpress. Both work individually, but they don't work when I combine them. Whenever I sort something and then click on page 2 button, my URL changes to this.
http://localhost:8888/?sort=company&s&s2#038;s&s2page/2
I need it to change to this, so it works.
http://localhost:8888/page/2/?sort=company&s&s2#038;s&s2
How do I accomplish this?
This is the function I am using
function custom_pagination($numpages = '', $pagerange = '', $paged='') {
if (empty($pagerange)) {
$pagerange = 2;
}
global $paged;
if (empty($paged)) {
$paged = 1;
}
if ($numpages == '') {
global $wp_query;
$numpages = $wp_query->max_num_pages;
if(!$numpages) {
$numpages = 1;
}
}
$pagination_args = array(
'base' => get_pagenum_link(1) . '%_%',
'format' => 'page/%#%',
'total' => $numpages,
'current' => $paged,
'show_all' => False,
'end_size' => 1,
'mid_size' => $pagerange,
'prev_next' => True,
'prev_text' => __('«'),
'next_text' => __('»'),
'type' => 'plain',
'add_args' => false,
'add_fragment' => ''
);
$paginate_links = paginate_links($pagination_args);
if ($paginate_links) {
echo "<nav class='custom-pagination'>";
echo "<span class='page-numbers page-num'>Page " . $paged . " of " . $numpages . "</span> ";
echo $paginate_links;
echo "</nav>";
}
And this is what I have on the page:
<?php
if (function_exists(custom_pagination)) {
custom_pagination($loop->max_num_pages,"",$paged);
}
?>
Thank you very much for your help :)