Wordpress WP_query pagination /paged/2 is not showing posts instead taking to index.php

Viewed 24

I have come across the issue where I call out a pagination for my WP_query posts on category.php page. The pagination appears fine and should be functional. As I click on page 2 or next it takes me to index.php instead of showing second page posts from my WP_query. As I change 'paged' to different numbers in my WP_query array the content updates. Why doesn't my page show different pages for my WP_query. So far I have tried so many things and I can't figure it out, I tried to change taxonomy names, resetting permalinks, different paginations but no luck.

<?php
$category = get_category( get_query_var( 'cat' ) );
$cat_id = $category->name;
?>

<?php

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 

$args = array(
    'post_type' => 'bananas',
    'posts_per_page' => 1,
    'paged' => $paged,
    'tax_query' => array(
        array (
            'taxonomy' => 'category',
            'field' => 'slug',
            'terms' => $cat_id,
        )
    ),
);
    
    $my_query = new WP_Query( $args ); ?>


<ul>

    <?php

    if( $my_query->have_posts() ) :
       
        while ($my_query->have_posts()) : $my_query->the_post(); 
        
     
        ?>
            
            <li>
           
            <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
   
                <?= get_the_post_thumbnail($post_item['ID'], 'full'); ?>
                </div>
    
                <h4><?php the_title(); ?></h4>
                <span class="title-description"><?= wp_trim_words( get_the_content(), 25, '..'); ?></span>

    </a>
        </li>
      
            <?php
        endwhile; endif;

    wp_reset_query();
?>

<?php

$total_pages = $my_query->max_num_pages;

if ($total_pages > 1){

    $current_page = max(1, get_query_var('paged'));

    echo paginate_links(array(
        'base' => get_pagenum_link(1) . '%_%',
        'format' => '/paged/%#%',
        'current' => $current_page,
        'total' => $total_pages,
        'prev_text'    => __('« prev'),
        'next_text'    => __('next »'),
    ));
}

?>
<?php wp_reset_postdata();?>
0 Answers
Related