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

<?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 ?

1 Answer
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.

Leave a Comment