WordPress pagination not working using WP_Query

Question

Ok I know there are a lot posts on this already but I can seem te find what is wrong with my code. Because pagination is still nog working. The weird thing is de same code and template work fine on an other site i’m using them on.

<?php

    $type = get_sub_field('type');
    $amount = get_sub_field('amount');
    $previousLabel = $labels['previous_label'];
    $nextLabel = $labels['next_label'];

?>

<div class="block-review block-review-<?php echo($type)?>">
    <div class="content-wrapper">
        <?php 
            if($type == 'list') {
                // get list of posts
                $pageQuery = (is_home())? 'page' : 'paged';
                $paged = (get_query_var($pageQuery)) ? get_query_var($pageQuery) : 1;
                $reviews = new WP_Query(
                    array( 
                        'post_type' => 'review', 
                        'posts_per_page' => $amount,
                        'paged' => $paged,
                        'orderby' => 'date',
                        'order' => 'DESC',
                        'meta_key' => 'meta_data_hide_review',
                        'meta_value' => '0'
                    )
                );
                // loop though reviews
                if ($reviews->have_posts()):
                    while($reviews->have_posts()): $reviews->the_post();
                        require('element/review-item.php');
                    endwhile;
                    ?>
                    <div style="display:none"><?php var_dump(get_query_var('page') . get_query_var('paged'))?></div>
                    <div class="review-pagination-wrapper">
                        <div class="review-pagination">
                            <?php 
                                echo paginate_links( array(
                                    'base'         => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
                                    'total'        => $reviews->max_num_pages,
                                    'current'      => max( 1, get_query_var( $pageQuery ) ),
                                    'format'       => '?' . $pageQuery . '=%#%',
                                    'show_all'     => false,
                                    'type'         => 'plain',
                                    'end_size'     => 2,
                                    'mid_size'     => 1,
                                    'prev_next'    => true,
                                    'prev_text'    => sprintf( '<i></i> %1$s', __( $previousLabel , 'text-domain' ) ),
                                    'next_text'    => sprintf( '%1$s <i></i>', __( $nextLabel , 'text-domain' ) ),
                                    'add_args'     => false,
                                    'add_fragment' => '',
                                ) );
                            ?>
                        </div>
                    </div>
                    <?php
                else:
                    // no posts
                endif;
                wp_reset_postdata();
            }
        ?>
    </div>
</div>

So the first page works fine, and pagination show up but i can’t navigate to the next pages. Any help would be very very very appreciated.

0
, user179536 12 months 0 Answers 80 views 0

Leave an answer