title: Ajax pagination in wordpress with custom post type on archive.php
body: <p>Wonder if anyone can help as this is driving me insane. I have an archive page with a list of news stories. Now these news stories are controlled by an ajax call to populate and change them based on drop downs which consist of custom taxonomies (3 of them in this case, topics, sectors and technologies). Anyway the problem im having is that i cannot get pagination to work on any of the posts. I no it has something to do with the ajax call and the function its calling but i cannot get it to work. I have managed to get it to display the pagination numbers but when i click them it takes me to my web address/wp-admin/wp-ajax.php which obviously is wrong. I havent been doing this long so any help or guidance would help.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>  var base = window.location.pathname + window.location.search;
    var technologies = document.querySelector('#category').value;
    var sectors = document.querySelector('#sectors').value;
    var topics = document.querySelector('#topics').value;
    var sort = document.querySelector('#sort').value;
    var type = window.location.pathname.split('/')[1];
    var ajaxurl = 'http://www.mywebsite.com/wp-admin/admin-ajax.php';
  
      jQuery.ajax({
          type: 'GET',
          url: ajaxurl,
          data: {
                  "action": "load_news",
                  tech: '*' ,
                  sector: '*' ,
                  topic: '*' ,
                  sorting: sort,
                  type:type,
                  base:base
          },
          success: function(response) {
             jQuery(".news-slider").html(response);
             return false;
          }
      });</code></pre>
  </div>
  </div>
  </p>
  
  <p>Above is my jquery ajax call and below is the functions.php </p>
  
  <pre><code>                    add_action( 'wp_ajax_nopriv_load_news', 'prefix_load_term_news' );
                  add_action( 'wp_ajax_load_news', 'prefix_load_term_news' );
                  function prefix_load_term_news () {
                                  $tech_id = $_GET[ 'tech' ];
                                  $sector_id = $_GET[ 'sector' ];
                                  $topic_id = $_GET[ 'topic' ];
                                  $sort_filter = $_GET['sorting'];
                                  $type = $_GET['type'];
                                  $base = $_GET[ 'base' ];
                                  $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
                                  $args = array (
                                                      'post_type' =&gt; $type,
                                                      'posts_per_page' =&gt;2,
                                                      'paged' =&gt; $paged,
                                                      'order' =&gt; $sort_filter,
                                                      'tax_query' =&gt; array(
                                                          'relation' =&gt; 'OR',
                                                              array(
                                                                  'taxonomy' =&gt; 'taxonomy-news',
                                                                  'field'    =&gt; 'id',
                                                                  'terms'    =&gt; $tech_id,
                                                              ),
                                                              array(
                                                                  'taxonomy' =&gt; 'category',
                                                                  'field'    =&gt; 'id',
                                                                  'terms'    =&gt; $sector_id,
                                                              ),
                                                              array(
                                                                  'taxonomy' =&gt; 'taxonomy-topics',
                                                                  'field'    =&gt; 'id',
                                                                  'terms'    =&gt; $topic_id,
                                                              ),
                                                      ),
                                               );
                          try {
                              $postslist = new WP_Query($args);
  
                              $big = 999999999; // This needs to be an unlikely integer
                          // For more options and info view the docs for paginate_links()
                          // http://codex.wordpress.org/Function_Reference/paginate_links
                          $paginate_links = paginate_links( array(
                              'base' =&gt; str_replace( $big, '%#%', get_pagenum_link($big) ),
                              'current' =&gt; max( 1, $postslist-&gt;get( 'paged' ) ),
                              'total' =&gt; $postslist-&gt;max_num_pages,
                          ) );
                          // Display the pagination if more than one page is found
                          if ( $paginate_links ) {
                              echo '&lt;div class="pagination"&gt;';
                              echo $paginate_links;
                              echo '&lt;/div&gt;&lt;!--// end .pagination --&gt;';
                          }
                          }
                          catch (Exception $error) {
                              echo 'An error occurred while loading news posts. Please try again.';
                          }
                          ?&gt;
                      &lt;?php   if ( $postslist-&gt;have_posts() ) :
                              while ( $postslist-&gt;have_posts() ) : $postslist-&gt;the_post();
                                  include('template-parts/content-archive-ajax.php');
                              endwhile;
                           wp_reset_postdata();
                   endif;
          }
  </code></pre>