title: WordPress pagination showing extra blank page after filtering past events
body: <p>I have a list of events that are displaying in date order, with events in the past being hidden.</p>
  
  <p>The issue is that in total, there are 3 pages of events, but once the past events are hidden, there are only enough events to fill 2 pages. However, a third, blank page is still present and can be accessed through the paging links.</p>
  
  <p>This is the code on my events list page:</p>
  
  <pre><code>&lt;?php $today = date("Ymd");?&gt;
  
  &lt;?php $paged = 1;
  if ( get_query_var('paged') ) $paged = get_query_var('paged');
  if ( get_query_var('page') ) $paged = get_query_var('page');
  query_posts( '&amp;post_type=upcomingevents&amp;paged=' . $paged );?&gt; 
  
  &lt;?php $loop = new WP_Query( array( 'post_type' =&gt; 'upcomingevents', 'paged'=&gt; $paged, 'meta_key' =&gt; 'start_date', 'meta_compare' =&gt; '&gt;=', 'meta_value' =&gt; $today, 'orderby' =&gt; 'meta_value_num', 'order' =&gt; 'ASC' )); ?&gt;
  &lt;?php while ( $loop-&gt;have_posts('post_type=upcomingevents') ) : $loop-&gt;the_post(); ?&gt;
  </code></pre>
  
  <p>And this is the paging code in my functions file:</p>
  
  <pre><code>function paginate() {
  global $wp_query, $wp_rewrite;
  $wp_query-&gt;query_vars['paged'] &gt; 1 ? $current = $wp_query-&gt;query_vars['paged'] : $current = 1;
  $pagination = array(
      'base' =&gt; @add_query_arg('page','%#%'),
      'format' =&gt; '',
      'total' =&gt; $wp_query-&gt;max_num_pages,
      'current' =&gt; $current,
      'show_all' =&gt; true,
      'type' =&gt; 'plain'
  );
  if ( $wp_rewrite-&gt;using_permalinks() ) $pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged' );
  if ( !empty($wp_query-&gt;query_vars['s']) ) $pagination['add_args'] = array( 's' =&gt; get_query_var( 's' ) );
  echo paginate_links( $pagination );
  </code></pre>
  
  <p>}</p>
  
  <p>I have also discovered a second issue, when moving to page 2 or 3 of results, the CSS class of current remains on the number 1 within the paging, so impossible to tell which page you are on.</p>
  
  <p>Any suggestions would be greatly appreciated, many thanks.</p>