title: Wordpress custom pagination "next page" not working
body: <p>I found this custom wordpress pagination somewhere and tried using it. The pagination and the "view all" functionality works fine but the problem is with the "next" and "previous" function. When click the "next button" it skips to the last page. Can you please help me debug this code? I am not really familiar with php, it's actually my first time integrating to wordpress. Thank you!</p>
  
  <pre><code> function numeric_pagination ($pageCount = 9, $query = null) {
          if ($query == null) {
              global $wp_query;
              $query = $wp_query;
          }
          if ($query-&gt;max_num_pages &lt;= 1) {
              return;
          }
          $pageStart = 1;
          $paged = $query-&gt;query_vars['paged'];
          // set current page if on the first page
          if ($paged == null) {
              $paged = 1;
          }
          // work out if page start is halfway through the current visible pages and if so move it accordingly
          if ($paged &gt; floor($pageCount / 2)) {
              $pageStart = $paged - floor($pageCount / 2);
          }
          if ($pageStart &lt; 1) {
              $pageStart = 1;
          }
          // make sure page start is
          if ($pageStart + $pageCount &gt; $query-&gt;max_num_pages) {
              $pageCount = $query-&gt;max_num_pages - $pageStart;
          }
      ?&gt;
  
      &lt;div id="pagination"&gt;
          &lt;?php
          if ($paged != 1) {
          ?&gt;
  
          &lt;a href="&lt;?php echo get_pagenum_link(1); ?&gt;" class="numbered page-number-first"&gt;&lt;span&gt;&amp;lsaquo;&amp;lsaquo; &lt;?php _e('Previous Page', 'rhinoplasty'); ?&gt;&lt;/span&gt;&lt;/a&gt;
  
          &lt;?php
          }
          if ($pageStart &gt; 1) {
              //echo 'previous';
          }
          for ($p = $pageStart; $p &lt;= $pageStart + $pageCount; $p ++) {
              if ($p == $paged) {
          ?&gt;
  
          &lt;span class="numbered page-number-&lt;?php echo $p; ?&gt; current-numeric-page"&gt;&lt;?php echo $p; ?&gt;&lt;/span&gt;
  
          &lt;?php } else { ?&gt;
  
          &lt;a href="&lt;?php echo get_pagenum_link($p); ?&gt;" class="numbered page-number-&lt;?php echo $p; ?&gt;"&gt;&lt;span&gt;&lt;?php echo $p; ?&gt;&lt;/span&gt;&lt;/a&gt;
  
          &lt;?php
              }
          }
          if ($pageStart + $pageCount &lt; $query-&gt;max_num_pages) {
              //echo "last";
          }
          if ($paged != $query-&gt;max_num_pages) {
          ?&gt;
  
          &lt;a href="&lt;?php echo get_pagenum_link($query-&gt;max_num_pages); ?&gt;" class="numbered page-number-last"&gt;&lt;span&gt;&lt;?php _e('Next Page', 'rhinoplasty'); ?&gt; &amp;rsaquo;&amp;rsaquo;&lt;/span&gt;&lt;/a&gt;
          &lt;?php } ?&gt;
          &lt;?php if(!$_GET['viewall']){ ?&gt;
          &lt;a href="&lt;?php  echo add_query_arg( array( 'viewall' =&gt; "true" ), get_pagenum_link(1) ); ?&gt;"&gt;View All&lt;/a&gt;
          &lt;?php } ?&gt;
      &lt;/div&gt;
  
      &lt;?php
       }
      if (isset($_GET['viewall']))
      {
          function view_allposts( $query ) {
              $query-&gt;set( 'posts_per_page', -1 );
          }
          add_action( 'pre_get_posts', 'view_allposts' );
      }
  </code></pre>