title: Why pagination is not working and gives a 404 error on the wordpress site?
body: <p>Good day! The problem is this: in the template category(the archive) the pagination is not working, when you click on page 2 of the 404 error. 
  Please help do not understand how to solve it, already all head broke</p>
  
  <p><strong>My loop:</strong></p>
  
  <pre><code>&lt;?php
  $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
  $arg = array(
    'cat' =&gt; get_queried_object_id(),
    'post_type'=&gt;'post',
    'posts_per_page'=&gt;9,
    //'order'=&gt;'desc',
    'paged' =&gt; $paged,
    );
  $query = new WP_query($arg);
  if($query-&gt;have_posts()) : ?&gt;
  &lt;section class="blog"&gt;
    &lt;?php
    echo '&lt;div class="row"&gt;';
    $i=0;
    $formcreated=false;
    while( $query-&gt;have_posts() ) :
      $query-&gt;the_post();
      // display post 
     endwhile;
     wp_reset_postdata();
  endif;
  ?&gt;
  
  &lt;div class="pagination"&gt;
    &lt;?php
         if (function_exists('custom_pagination')) {
           custom_pagination($query-&gt;max_num_pages,"",$paged);
         }
       ?&gt;
     &lt;?php wp_reset_postdata(); ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>And my custom pagination:</strong></p>
  
  <pre><code>function my_post_queries( $query ) {
      // do not alter the query on wp-admin pages and only alter it if it's the main query
      if (!is_admin() &amp;&amp; $query-&gt;is_main_query()){
  
          // alter the query for the home and category pages
  
  
          if(is_category()){
              $query-&gt;set('posts_per_page', 1);
              $query-&gt;set('post_type','product');
          }
  
      }
  }
  add_action( 'pre_get_posts', 'my_post_queries' );
  
  function custom_pagination($numpages = '', $pagerange = '', $paged='') {
  
    if (empty($pagerange)) {
      $pagerange = 2;
    }
  
    /**
     * This first part of our function is a fallback
     * for custom pagination inside a regular loop that
     * uses the global $paged and global $wp_query variables.
     *
     * It's good because we can now override default pagination
     * in our theme, and use this function in default queries
     * and custom queries.
     */
    global $paged;
    if (empty($paged)) {
      $paged = 1;
    }
    if ($numpages == '') {
      global $wp_query;
      $numpages = $wp_query-&gt;max_num_pages;
      if(!$numpages) {
          $numpages = 1;
      }
    }
  
    /**
     * We construct the pagination arguments to enter into our paginate_links
     * function.
     */
    $pagination_args = array(
      'base'            =&gt; get_pagenum_link(1) . '%_%',
      'format'          =&gt; 'page/%#%',
      'total'           =&gt; $numpages,
      'current'         =&gt; $paged,
      'show_all'        =&gt; False,
      'end_size'        =&gt; 1,
      'mid_size'        =&gt; $pagerange,
      'prev_next'       =&gt; True,
      'prev_text'       =&gt; __('&amp;#60;'),
      'next_text'       =&gt; __('&amp;#62;'),
      'type'            =&gt; 'plain',
      'add_args'        =&gt; false,
      'add_fragment'    =&gt; ''
    );
  
    $paginate_links = paginate_links($pagination_args);
  
    if ($paginate_links) {
      echo "&lt;nav class='custom-pagination'&gt;";
        echo $paginate_links;
      echo "&lt;/nav&gt;";
    }
  
  }
  </code></pre>