• Shashank Naithani

    (@shashank-naithani)


    On every page i m getting 404 error page. If i m click on the next for the second page.

    My code for the CPT is

    <?php
                       // WP_Query arguments
    
                       global $query;
                      $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                       $args = array(
                         'post_type' => 'img_gallery',
                         'post_status' => 'publish',
                         'posts_per_page' => 12,
                         'paged'    => $paged,
                         'ignore_sticky_posts'=> 1,
                         'order'=> 'ASC',
                         'orderby'=> 'ID'
                       );
                       // The Query
                       $query = new WP_Query( $args );
                       foreach( $query->posts as $post ) :
                     // echo "<pre>"; print_r($post);
                      //echo print_r($post);
                   ?>
            <div class="grid_3 put-left box ">
                <div class=" video" >
                        <figure>
                           <a class="fancybox" href="<?php echo wp_get_attachment_url(get_post_thumbnail_id()); ?>" data-fancybox-group="gallery" title="<?php the_title(); ?>">
                            <?php the_post_thumbnail( 'photos' ); ?>
                           </a>
                         </figure>
                        <h2 class="videoTitle"><?php the_title(); ?> </h2>
                </div>
            </div>
           <?php
                endforeach
                ?>
    <nav class="pagination">
    
              <?php echo custom_pagination(); ?>
    
      </nav>

    The pagination function is

    function custom_pagination() {
    
      global $query;
    
                $big = 999999999; // need an unlikely integer
    
                echo paginate_links( array(
    
                  'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    
                  'format' => '?paged=%#%',
    
                  'current' => max( 1, get_query_var('paged') ),
    
                  'total' => $query->max_num_pages,
    
                  'prev_next'    => True,
    
                  'prev_text'    => __('? Previous'),
    
                  'next_text'    => __('Next ?'),
    
                  'type'  => 'list',
    
                ) );
    
    }

    I m confused everything is right as i do every time but what i did wrong.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Shashank Naithani

    (@shashank-naithani)

    If you go to my site https://prideofuttrakhand.org/photos/

    You will see the pagination is giving correct url, however if I click on the next I m getting 404 error.

    Thread Starter Shashank Naithani

    (@shashank-naithani)

    Someone pls help My all other CPt are working fine and give me the second pages correctly. But i m getting 404 error on the Photos Gallery The CPT is

    function create_image_gallery() {
    
      register_post_type( 'img_gallery',
    
        array(
    
          'labels' => array(
    
            'name' => __( 'Photos' ),
    
            'singular_name' => __( 'Photo' )
    
          ),
    
          'public' => true,
    
          'publicly_queryable' => true,
    
          'capability_type'     => 'post',
    
          'has_archive' => false,
    
          'menu_icon' => 'dashicons-images-alt2',
    
          'menu_position' => 32,
    
         'rewrite' => array( 'with_front'=> false,'slug' => 'photos' ),
    
          'supports' => array('title', 'editor', 'excerpt', 'thumbnail'),
    
        )
    
      );
    
    }
    
    function image_gallery_flush_rules(){
      //defines the post type so the rules can be flushed.
      create_image_gallery();
      //and flush the rules.
      flush_rewrite_rules();
    }
    
    add_action('after_theme_switch', 'image_gallery_flush_rules');
    add_action('init', 'create_image_gallery');

    you can see the page here at https://prideofuttrakhand.org/photos/

    all other pages are going to second page but this one i don’t know what is wrong.

    Please help me…….

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Getting 404 For the /page/2’ is closed to new replies.