• 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( '&larr; Previous' ); ?></div>
                          <div class="alignright"><?php next_posts_link( 'Next &rarr;' ); ?></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)
  • Thread Starter kylemint23

    (@kylemint23)

    here is my code for the custom taxonomy:

    public function register_ctax_product_cat() {
                $labels = array(
                    'name' => __( 'Product Categories', 'genesis_product_cat'),
                    'singular_name' => __( 'Product Category', 'genesis_product_cat'),
                    'search_items' =>  __( 'Search Product Categories', 'genesis_product_cat'),
                    'popular_items' => __( 'Popular Product Categories', 'genesis_product_cat' ),
                    'all_items' => __( 'All Product Categories', 'genesis_product_cat'),
                    'parent_item' => __( 'Parent Product Category', 'genesis_product_cat'),
                    'parent_item_colon' => __( 'Parent Product Category:', 'genesis_product_cat'),
                    'edit_item' => __( 'Edit Product Category', 'genesis_product_cat'),
                    'update_item' => __( 'Update Product Category', 'genesis_product_cat'),
                    'add_new_item' => __( 'Add New Product Category', 'genesis_product_cat'),
                    'new_item_name' => __( 'New Product Category Name', 'genesis_product_cat'),
                    'separate_items_with_commas' => __( 'Separate product categories with commas', 'genesis_product_cat' ),
            	    'add_or_remove_items' => __( 'Add or remove product categories', 'genesis_product_cat' ),
            	    'choose_from_most_used' => __( 'Choose from the most used product categories', 'genesis_product_cat' ),
            	    'menu_name' => __( 'Product Categories', 'genesis_product_cat' )
                );
                $args = array(
                    'labels' => $labels,
                    'label' => __( 'Product Categories', 'genesis_prod'),
                    'update_count_callback' => '_update_post_term_count',
                    'public' => true,
                    'show_in_nav_menus' => true,
                    'show_ui' => true,
                    'show_tagcloud' => false,
                    'show_admin_column' => true,
                    'hierarchical' => true,
                    'rewrite' => array('slug' => 'product_category','with_front' => FALSE),
                    'query_var' => true
                );
                register_taxonomy( 'product_category', array( 'product' ), $args );
            }

    and for my CPT product:

    public function register_cpt_product() {
                $labels = array(
            		'name' => __( 'Products', 'genesis_prod' ),
            		'singular_name' => __( 'Product', 'genesis_prod' ),
            		'add_new' => __( 'Add Product', 'genesis_prod' ),
            		'add_new_item' => __( 'Add New Product', 'genesis_prod' ),
            		'edit' => __( 'Edit', 'genesis_prod' ),
            		'edit_item' => __( 'Edit Product', 'genesis_prod' ),
            		'new_item' => __( 'New Product', 'genesis_prod' ),
            		'view' => __( 'View Product', 'genesis_prod' ),
            		'view_item' => __( 'View Product', 'genesis_prod' ),
            		'search_items' => __( 'Search Products', 'genesis_prod' ),
            		'not_found' => __( 'No Products found', 'genesis_prod' ),
            		'not_found_in_trash' => __( 'No Products found in trash', 'genesis_prod' ),
            		'parent_item_colon' => __( 'Parent Product:', 'genesis_prod' ),
            		'parent' => __( 'Parent Product', 'genesis_prod' ),
            		'menu_name' => __( 'Products', 'genesis_prod' )
                );
                $args = array(
                    'labels' => $labels,
                    'hierarchical' => true,
                    'description' => 'Add posts as product custom post type',
                    'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'page-attributes' ),
                    'taxonomies' => array( 'product_category' ),
                    'public' => true,
                    'show_ui' => true,
                    'show_in_menu' => true,
                    'menu_icon' => 'https://client.yourgreenva.com/genesis/wp-content/uploads/2013/10/cart_full.png',
                    'show_in_nav_menus' => true,
                    'publicly_queryable' => true,
                    'exclude_from_search' => false,
                    'has_archive' => true,
                    'query_var' => true,
                    'can_export' => true,
                    'rewrite' => array( 'slug' => 'product','with_front' => FALSE),
                    'capability_type' => 'post'
                );
                register_post_type( 'product', $args );
            }

    I just can’t figured it out why im getting the 404 page not found,
    even when I already use the plugin wp-pagenavi..but in the first code I added above, I already removed it cause Im still having the same issue even changing my permalinks to default but doesnt work, then back to post name again still have that issue..
    Please help..

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.