I am trying to change pages when I search by category on my website. When I am not searching under a certain category I can switch pages fine but when I am searching for a category I am unable to switch pages.
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$orderby = ( get_query_var( 'orderby' ) ) ? absint( get_query_var( 'orderby' ) ) : 'display_name';
if($_GET['search'] && !empty($_GET['search'])) {
$search = $_GET['search'];
}
if($_GET['category'] && !empty($_GET['category'])) {
$category = $_GET['category'];
}
$args = array(
'orderby' => 'rand',
'number' => 7,
'paged' => $paged,
'search' => '*'.esc_attr( $search ).'*',
'meta_query' => array (
array(
'key' => 'organization_category_2',
'value' => $category,
'compare' => 'like'
)
)
);
$user_query = new WP_User_Query($args);
And my pagination links:
<?php
$total_user = $user_query->total_users;
$total_pages=ceil($total_user/7);
echo paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => '?paged=%#%',
'current' => $paged,
'total' => $total_pages,
'prev_text' => 'Previous',
'next_text' => 'Next',
'type' => 'list',
));
?>
Whenever I try and do a search I get a url like this:
https://mywebsite.ca/directory/?search&category=Government#038;category=Government&paged=2