Custom Taxonomy Pagination Not Working

Question

I have a custom taxonomy called by "Singers" related to the posts and Created custom page with the same name (singers.php) as archive to showing taxonomies in there.
Now pagination in this custom archive page is not working.

So this is my query codes:

            <?php
              $term = get_queried_object();
            ?>
            <?php
                $the_query = get_terms(
                array(
                'taxonomy'   => 'singers',
                'hide_empty' => true,
                'orderby' => 'name',
                'posts_per_page' => 12,
                'paged' => get_query_var( 'paged' ),
                )
                );  
                if ( ! empty( $the_query ) && is_array( $the_query ) ) {
                foreach ( $the_query as $term ) { 
            ?>      
            <?php while ($the_query->have_posts()) : $the_query->the_post(); ?>

             // Content Here

            <?php endwhile; ?>
            <?php
            }
            } 
            ?>

and pagination code is:

            <?php global $wp_query; if ($wp_query->max_num_pages > 1) : ?>  
            <div class="col-xl-12 col-lg-12 col-md-12">                                 
                <div class="m24_cover mt-40 mb-20">
                    <?php mytheme_pagination(); ?>
                </div>                      
            </div>  
            <?php endif; ?> 

mytheme function (in functions.php):

function mytheme_pagination() {

global $wp_query;

if ( $wp_query->max_num_pages <= 1 ) return; 

$big = 999999999; // need an unlikely integer

$pages = paginate_links( array(
        'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
        'format' => '?paged=%#%',
        'current' => max( 1, get_query_var('paged') ),
        'total' => $wp_query->max_num_pages,
        'type'  => 'array',
        'prev_text' => __( '<i class="flaticon-left-arrow"></i>', 'mytheme' ),
        'next_text' => __( '<i class="flaticon-right-arrow"></i>', 'mytheme' ),
        
    ) );
    if( is_array( $pages ) ) {
        $paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged');
        echo '<div class="pagination-wrap"><ul class="pagination">';
        foreach ( $pages as $page ) {
                echo "<li>$page</li>";
        }
       echo '</ul></div>';
        }
}

There is nothing show for pagination in the bottom and all taxonomies are showing up together in archive page.

Please edit my code. Thanks

0
emco 2 months 0 Answers 13 views 0

Leave an answer