I have an issue with pagination on category.php using a custom post type query.

my code :

 <section class="products-list">

            $current_page   = get_queried_object();
            $category       = $current_page->post_name;          

            $args = array( 'post_type' => 'product_elm', 'category_name' => $category, 'posts_per_page' => 2);
            $the_query = new WP_Query( $args );

            if ( $the_query->have_posts() ) {
                while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
            <div class="item">
                <a href="<?php the_permalink() ?>">
                    <div class="img">
                        <?php the_post_thumbnail(); ?>   
                    <h2> <?php the_title(); ?></h2>


            next_posts_link( 'Older Entries', $the_query->max_num_pages );
            previous_posts_link( 'Newer Entries' );

When i click on "older entries" i have a "not found" page.

The url seems good though: /category/chaudieres-a-condensation/page/2/

thank you for your help.

Best Regards

Your Answer

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

Browse other questions tagged or ask your own question.