Pagination not working on custom query on a page

I have a custom query on a page (it is not an archive page), it works just fine, but I want pagination and it is not working at all…

                        <?php 
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                                if(have_posts() ):
   $args = array( 'post_type' => 'store',
                  //    'posts_per_page' => 9,
                   'paged' => $paged,
                  'meta_key' => 'store_client_type',
                  'tax_query' => array(
                        array(
                            'taxonomy' => 'style',
                            'field'    => 'slug',
                            'terms'    => $style,
                        )
                    ),
                 'meta_query' => array(
                        'relation' => 'AND',
                        array(
                        'plan_clause' => array(
                                        'key'  => 'store_client_type_plan',
                                        'compare'   => 'EXISTS',
                                        ),
                                    ),
                        array(
                        'relation' => 'AND',
            )
                                ),
                  'orderby' => array(
                                'plan_clause'  => 'desc',
                            )   
                 ); 
    $loop = new WP_Query( $args );
        while($loop->have_posts()):  $loop->the_post(); ?>
                            
                                <div class="col-lg-4 col-md-6 col-sm-12 center">
                                    <div class="blog-article-card pt-2">
                                        <h4><?php the_title(); ?></h4>
                                        </div>
                                    </div>
                                </div>
                                <?php     
        endwhile;  
        endif;
                the_posts_pagination(); 
        wp_reset_query();   
                    ?>

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

SOLVED
with the magic of paginate_links (after the endwhile)

<?php
$big = 999999999; // need an unlikely integer
 
echo paginate_links( array(
    'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    'format' => '?paged=%#%',
    'current' => max( 1, get_query_var('paged') ),
    'total' => $loop->max_num_pages
) ); ?>


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x