Custom Post Type Pagination On page 2 not working/ 404 page not found
-
Hello Guys, I have problem on my custom post type pagination, when the
NEXT
button is click its url is
/product_category/junk-mills/page/2/
but shows page not found.heres my code:
global $wp_query; if ( empty($paged) ) { if ( !empty( $_GET['paged'] ) ) { $paged = $_GET['paged']; } elseif ( !empty($wp->matched_query) && $args = wp_parse_args($wp->matched_query) ) { if ( !empty( $args['paged'] ) ) { $paged = $args['paged']; } } if ( !empty($paged) ) $wp_query->set('paged', $paged); } $temp = $wp_query; $wp_query = null; $wp_query = new WP_Query(); $args = array( 'post_type' => 'product', 'posts_per_page' => 2, //remember posts per page should be less or more that what's set in general settings 'paged' => $paged, 'order' => 'ASC', 'orderby'=> 'menu_order', 'tax_query' => array(array( 'taxonomy' => 'product_category', 'field' => 'slug', 'terms' => $slug) ) ); $wp_query -> query($args); if ( $wp_query->have_posts() ) : while ($wp_query->have_posts()) : $wp_query->the_post(); ?> <div class="product"> <a class="product-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <a href="<?php the_permalink(); ?>"> <?php the_content(); ?> </a> </div> <!--end product--> <?php endwhile; else: ?> <div class="notice-error">Sorry no products were found in this category.</div> <?php endif; ?> <?php //wp_reset_query(); ?> </div><!-- .single_post_content --> <div class="wp-pagenavi pagination"> <div class="alignleft"><?php previous_posts_link( '← Previous' ); ?></div> <div class="alignright"><?php next_posts_link( 'Next →' ); ?></div> </div><!--end pagination--> <?php //wp_reset_query(); wp_reset_postdata(); /** Restore Query */ $wp_query = null; $wp_query = $temp;
I already installed & use the wp_pagenavi() but still after clicking the page 2 it show the page not found.
Any help would be appreciated. Thanks a lot!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Custom Post Type Pagination On page 2 not working/ 404 page not found’ is closed to new replies.