Custom Taxonomy Pagination show 404 from page 2

admin

Administrator
Staff member
I have added pagination code(<a href="https://www.wpblog.com/use-wp_query-to-create-pagination/" rel="nofollow noreferrer">https://www.wpblog.com/use-wp_query-to-create-pagination/</a>) im my website. This code works well in my page templates. But when i do the same coding in my custom taxonomy template it is not working from page 2. It goes to error page. Pleas help.

Code Here for taxonomy-somename.php

Code:
    &lt;?php
/**
 * The template for displaying archive pages.
 *
 * Learn more: http://codex.wordpress.org/Template_Hierarchy
 *
 * @package Sydney
 */

get_header();
?&gt;


    &lt;div id="primary" class="content-area col-md-9"&gt;

        &lt;main id="main" class="post-wrap" role="main"&gt;

&lt;ul id="service-list"&gt;
&lt;?php
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$paged = (get_query_var( 'page' )) ? get_query_var( 'page' ) : 1;
$aud_query = new WP_Query(
  array(
    'post_type' =&gt; 'attachment',
    'post_status' =&gt; 'inherit',
    //'post_mime_type' =&gt; 'image',
    'post_mime_type' =&gt; 'audio',
    'posts_per_page' =&gt; 2,
    'paged'          =&gt; $paged,
    'post_parent__in' =&gt; $query-&gt;posts,
    'order' =&gt; 'DESC',
    'tax_query' =&gt; array(
        array(
            'taxonomy' =&gt; 'mymusic',
            'field'    =&gt; 'slug',
            'terms'    =&gt; $term-&gt;slug,
        ),
    ),
    )
);
?&gt;
          &lt;!----start--------&gt;
&lt;?php  if( $aud_query-&gt;have_posts() ) : ?&gt;
&lt;?php while($aud_query-&gt;have_posts()) :  $aud_query-&gt;the_post(); ?&gt;
&lt;?php echo
get_the_title($attach_id);
echo '&lt;br&gt;';
?&gt;
&lt;?php endwhile ?&gt;
        &lt;?php
        if (function_exists("pagination")) {
          pagination($aud_query-&gt;max_num_pages);
      }
        ?&gt;           
        &lt;?php else :?&gt;
        &lt;h3&gt;&lt;?php _e('404 Error: Not Found', ''); ?&gt;&lt;/h3&gt;

    &lt;?php endif; wp_reset_postdata();?&gt;


&lt;/ul&gt;&lt;!-- #service-list --&gt;
        &lt;/main&gt;&lt;!-- #main --&gt;
    &lt;/div&gt;&lt;!-- #primary --&gt;


&lt;?php get_footer(); ?&gt;