title: WordPress plugin pagination not working correctly
body: <p>I've created a function that uses the built-in function <code>paginate_links</code>.</p>
  
  <p>But the pagination isn't working correctly because the URL is being written wrong.</p>
  
  <p>The URL I want looks like this <code>domain.com/properties/page/2/?foo=bar</code></p>
  
  <p>The URL that is being output is <code>domain.com/properties/?foo=bar/page/2/</code></p>
  
  <p>Here's my code</p>
  
  <pre><code>function paginate($max_num_pages) {
      global $wp_query, $wp_rewrite;
      $wp_query-&gt;query_vars['page'] &gt; 1 ? $current = $wp_query-&gt;query_vars['page'] : $current = 1;
      $pagination = array(
          'base' =&gt; @add_query_arg('page','%#%'),
          'format'       =&gt; '',
          'total'        =&gt; $max_num_pages,
          'current'      =&gt; $current,
          'show_all'     =&gt; true,
          'end_size'     =&gt; 1,
          'mid_size'     =&gt; 2,
          'prev_next'    =&gt; True,
          'prev_text'    =&gt; __('« Previous'),
          'next_text'    =&gt; __('Next »'),
          'type'         =&gt; 'plain',
          'add_args'     =&gt; false,
          'add_fragment' =&gt; ''
      );
  
      if( $wp_rewrite-&gt;using_permalinks() ) 
          $pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'page' );
  
      if( !empty($wp_query-&gt;query_vars['s']) ) 
          $pagination['add_args'] = array( 's' =&gt; get_query_var( 's' ) );
  
      echo paginate_links( $pagination );
  }
  </code></pre>