Pagination while keeping the filters

I code a page that shows the post results with a couple of filters (the visitor can filter by country and time) and the result is paginated:

$posts_per_page = 10;
$paged = ( get_query_var( ‘paged’ ) ) ? get_query_var( ‘paged’ ) : 1;
$query_args = array(‘posts_per_page’ => $posts_per_page, ‘paged’ => $paged , “enable_filter” => array(“country”, “time”));
$query = WP_Query ($query_args);
$total_post = $query->found_posts;
$pages = $total_post / $posts_per_page;
if ($total_post % $posts_per_page) $pages=$pages+1;
$args = array(
‘base’ => ‘%_%’,
‘format’ => ‘?paged=%#%’,
‘total’ => $pages,
‘current’ => 0,
‘show_all’ => true,
‘end_size’ => 1,
‘mid_size’ => 2,
‘prev_next’ => true,
‘prev_text’ => __(‘” Previous’),
‘next_text’ => __(‘Next »’),
‘type’ => ‘plain’,
‘add_args’ => false,
‘add_fragment’ => ”,
‘before_page_number’ => ”,
‘after_page_number’ => ”
);
echo paginate_links($args);
?>

The pagination works just fine, the problem is when I apply a filter. When I filter by country and/or time the pagination for the results shows right but when I click on page number 2 I get all the results, meaning that the filters are not applied any longer.
How can I preserve the filters during the pagination? Is it done by adding the result to the argument base? If so, is there another option to pass the parameters by post?

Thanks

Read more here:: Pagination while keeping the filters

Leave a Reply

Your email address will not be published. Required fields are marked *