error 404 on pagination when modifying a new wp_query argument ‘post_per_page’

Question

I’m using WP_Query to generate an archive custom posts type. In the settings of wordpress I have set to 12 the number of posts to see per page.
But on this particular archive page I want to see 6 custom posts max.

Here’s my code:

<div class="future_event">
        <?php
            $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
            $argsFuture = array(
                'posts_per_page' => 6,
                'paged' => $paged,
                'post_type' => 'agenda',
                'orderby'   => 'meta_value_num',
                'order' => 'ASC',
                'meta_key'  => 'date',
                'orderby' => 'meta_value',
                'meta_query' => array(
                        array(
                        'key'     => 'date',
                        'value'   => date('Ymd'),
                        'compare' => '>=',
                ),
                ),
            );
            $queryFuture = new WP_Query( $argsFuture );

            if( $queryFuture->have_posts() ) : while( $queryFuture->have_posts() ) : $queryFuture->the_post();

                $thisDay = date("Ymd");
                $thisDatePost = get_field('date');
                $thisDayPost = date("Ymd", strtotime($thisDatePost));
                ?>

                <article class="post_archive">
                    //my article code here
                </article>

            <?php endwhile; endif; ?>
            <?php wp_reset_postdata(); ?>
            
            <nav>
                <?php wp_pagenavi( array( 'query' => $queryFuture ) ); ?>
            </nav>
            
        </div>

When I set to 12 the ‘posts_per_page’ it’s ok. But I need to set 6.
Thanks a lot

0
Eloi G 2 months 0 Answers 10 views 0

Leave an answer