Multiple WP_Query loops with Pagination Not Working

Please can anyone help me out here? I’m really stucked with this code.

I want to create a multi post loop on my home page with each loop having its own pagination.

The first loop is for recent post, while the second is for popular post and the last is for recommended posts.

Only the first loop pagination is working perfectly but the other two are not working. What could be wrong with my code?
I know almost nothing about PHP.

I actually got the code from here ( https://wordpress.stackexchange.com/questions/47259/multiple-wp-query-loops-with-pagination#= )

Can I also rap the pagination ‘next’ link with a div?
Here is the code.
`

    <?php
            $paged1 = isset( $_GET['paged1'] ) ? (int) $_GET['paged1'] : 1;
            $paged2 = isset( $_GET['paged2'] ) ? (int) $_GET['paged2'] : 1;
            $paged3 = isset( $_GET['paged3'] ) ? (int) $_GET['paged3'] : 1;

            // Custom Loop with Pagination 1
            // http://codex.wordpress.org/Class_Reference/WP_Query#Usage
            $args1 = array(
                'paged'          => $paged1,
                'posts_per_page' => 8,
            );
            $query1 = new WP_Query( $args1 );

            while ( $query1->have_posts() ) : $query1->the_post();

            get_template_part( 'template-parts/content', get_post_format() );

            endwhile;

            // http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters
            $pag_args1 = array(
                'format'  => '?paged1=%#%',
                'current' => $paged1,
                'total'   => $query1->max_num_pages,
                'add_args' => array( 'paged2' => $paged2 )
            );
            echo paginate_links( $pag_args1 );
        ?>




         <div class="popular">
        <?php

             $popular_days_ago = "$popular_days days ago";
             $recent = new WP_Query
             (array( 'posts_per_page' => $number,
              'orderby' => 'meta_value_num', 
              'order' => 'DESC', 
              'meta_key' => 'post_views_count', 
              'date_query' => array( array( 'after' => $popular_days_ago )) ));

             $paged1 = isset( $_GET['paged1'] ) ? (int) $_GET['paged1'] : 1;
            $paged2 = isset( $_GET['paged2'] ) ? (int) $_GET['paged2'] : 1;
            $paged3 = isset( $_GET['paged3'] ) ? (int) $_GET['paged3'] : 1;

           // Custom Loop with Pagination 2
           $args2 = array(
            'paged'          => $paged2,
            'posts_per_page' => 2,
        );


        while ( $recent->have_posts() ) : $recent->the_post();
        get_template_part( 'template-parts/content-pop', get_post_format() );
        endwhile;

        $pag_args2 = array(
            'format'  => '?paged2=%#%',
            'current' => $paged2,
            'total'   => $recent->max_num_pages,
            'container'   => 'ul',
            'add_args' => array( 'paged1' => $paged1 )
        );
        echo paginate_links( $pag_args2 );

        ?>
    </div>

<?php

$paged1 = isset( $_GET['paged1'] ) ? (int) $_GET['paged1'] : 1;
$paged2 = isset( $_GET['paged2'] ) ? (int) $_GET['paged2'] : 1;
$paged3 = isset( $_GET['paged3'] ) ? (int) $_GET['paged3'] : 1;


            // Custom Loop with Pagination 3
            $args2 = array(
                'paged'          => $paged3,
                'posts_per_page' => 3,
            );
            $query3 = new WP_Query( $args3 );
            $query3 = new WP_Query(array( 'cat' => $categories, 'posts_per_page' => $number )); 

            while ( $query3->have_posts() ) : $query3->the_post();
            get_template_part( 'template-parts/content-catlist', get_post_format() );

            endwhile;

            $pag_args3 = array(
                'format'  => '?paged3=%#%',
                'current' => $paged3,
                'total'   => $query3->max_num_pages,
                'add_args' => array( 'paged1' => $paged1 )
            );
            echo paginate_links( $pag_args3 );
        ?>

`

0

Leave a Comment