Getting 404 on taxonomy page

i’ve created a custom taxonomy template for my taxonomy and custom post type,

custom post type name is “ecommerce” custom taxonomy is “ecommerce_categories”, the problem is with the pagination it shows correctly that there are 2 pages with posts inside it but when i click on page 2 i get 404 page, this happens only when i’m on the taxonomy page, i’ve also created a custom page template that does the same as the taxonomy file and the pagination works here (on the custom page template) the problem is only when i’m on the taxonomy category page. This is the code of the file taxonomy-ecommerce_categories.php

Read More
<?php 
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $term = $wp_query->queried_object;

        $shop_loop = new WP_Query( array( 'post_type' => 'ecommerce', 'ecommerce_categories' => $term->name, 'posts_per_page' => 2, 'orderby' => 'menu_order', 'paged'=>$paged ) ); ?>

        <?php while ( $shop_loop->have_posts()  ) : $shop_loop->the_post(); ?>

                // here is my loop code with divs links etc.. etc...

        <?php endwhile;?>
        <div class="clearfix"></div>
        <?php if(function_exists('wp_pagenavi')) { wp_pagenavi( array( 'query' => $shop_loop ) ); } ?>

I see the pagination but when i click on page 2 or page 3 i get 404 error page this happen with any permalink setting and also if i change the pagination from the wp pagenavi plugin to the wordpress default one using this code

<?php wp_link_pages(); ?> or previous_post_link and next_post_link 

i can’t see it nothing is displayed below posts.

How can i fix this ? what i’m doing wrong ?

Related posts

Leave a Reply

2 comments

  1. I’ve solved this for myself with rewrite rule.

    The story: I have "piece" custom post type, taxonomy "media_tag" with "m_audio" term and taxonomy "genre_tag" with "g_sacred", "g_folk" etc. And I want to have an URL like /piece/audio/<genre> to access archives.

    So, now I have in my functions.php:

    add_filter( 'rewrite_rules_array', 'my_insert_rewrite_rules' );
    function my_insert_rewrite_rules( $rules ) {
      $newrules = array();
      // audio pieces with g_sacred tax:
      $newrules['piece/audio/([a-z]+)(/page/([0-9]+))?'] =
          'index.php?post_type=piece&media_tag=m_audio'
          . '&genre_tag=g_$matches[1]&paged=$matches[3]';
    
      return $newrules + $rules;
    }
    

    and nothing in taxonomy-media_tag-m_audio.php template.

    Hope this helps.

    Also, I have this in my functions.php:

    // add_action( 'wp_loaded','my_flush_ALL_rules' );
    function my_flush_ALL_rules(){
      global $wp_rewrite;
      $wp_rewrite->flush_rules();
    }
    

    And I uncomment add_action for a moment to flush rules after changes.

  2. Hi there! It sounds like you’ve put a lot of work into creating this custom taxonomy template for your ecommerce site. I’m sorry to hear that you’re experiencing issues with the pagination on the taxonomy category page.

    Have you tried checking your permalink settings to make sure they’re set up correctly? Sometimes, incorrect settings can cause 404 errors on certain pages. Additionally, have you tried using a plugin like WP-PageNavi to handle your pagination? It’s possible that this plugin could help resolve the issue you’re facing.

    One other thing to consider is whether there are any conflicting plugins or code snippets that could be causing this problem. Have you tried disabling other plugins or temporarily removing any custom code to see if that fixes the issue?

    I hope this helps! If you have any further details or information about the issue, please let us know. Additionally, have you found any other solutions or workarounds that have helped with pagination on custom taxonomy templates? I’m always interested in learning