• pagination works everywhere on my site but it isnt working in category.php. When i click page 2 it goes to… domain.com/category/cat-slug/page/2

    by the way this is showing custom post types within certain categories (no actual plain ‘posts’)

    But when the page loads its just the 404 page?

    In permalinks I have /%postname%/ although I have set category base to ‘category’ just to be safe.

    I also know this is kind of a convoluted way of doing it but i wasnt sure a better way.

    <?php
    
    get_header(); ?>
    
    <div class="home-gradient">
    <div id="container">
    <div class="content-wrap">  
    
    <?php 
    
        $uri = $_SERVER['REQUEST_URI'];
        $elms = explode('/', $uri);
    
        $categ = get_category_by_slug($elms[3]);
        $categ_id = $categ->term_id;
    
        if ( get_query_var('paged') ) {
        $paged = get_query_var('paged');
      } elseif ( get_query_var('page') ) {
        $paged = get_query_var('page');
      } else {
        $paged = 1;
      }
    
      $myquery = new WP_Query(array(
            'post_type' => 'any',
                'paged' => $paged,
                'posts_per_page' => 1,
          'cat' => $categ_id)
            );
    
            while ( $myquery->have_posts() ) : $myquery->the_post(); 
    
            $img_id = get_post_meta($post->ID,'main_image',true);
            $img_url = wp_get_attachment_url($img_id);
    
        ?>
    blah blah code here for output
    
        <?php
    
      endwhile;
       wp_pagenavi( array( 'query' => $myquery ) );
       ?>
  • The topic ‘Custom post type pagination /page/2 is giving a 404’ is closed to new replies.