0

I'm creating custom numbered pagination for custom taxonomy archive page. So, I have no problem with displaying pagination, with proper links display, etc.

However, when I click a link above page number 2 (e.g. page 3, like:

my-website.com/page/3/?my_category=some-term

i get 404 - page does not exist.

The category contains over 60 posts, and there should be 8 pages, but only the first and second one are displayed properly

my-website.com/?my_category=some-term

and

my-website.com/page/2/?my_category=some-term

but everything above this gives 404.

This is my WP_Query in this taxonomy template:

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

$args = array(
  'posts_per_page' => 8,
  'orderby' => 'title',
  'tax_query' => array(
       array(
          'taxonomy' => $qobj->taxonomy,
          'field' => 'id',
          'terms' => $qobj->term_id
       )
  ),
  'paged' => $paged
);

and

$wp_query = new WP_Query( $args );
3

Drop your custom query and go back to the default loop. Never replace the main query on the home page or any kind of archive page with a custom query. Use pre_get_posts to alter the main query variables before the main query runs

Your taxonomy archive page should look like this

if ( have_posts() ) {
    while ( have_posts() ) {
        the_post();

        // Your markup and template tags

    }
}
2
  • Ill accept this after I test it. Would youcare to elaborate why this is - why custom query is a bad idea?
    – tonino.j
    May 17 '15 at 23:14
  • 1
    You should read this post. I have explained everything in there. Hope that will answer your question beter :-). Enjoy May 18 '15 at 3:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.