WordPress pagination not working correctly

WordPress pagination not working after first wp_query. I am performing some operations on the data returned by first wp_query object. but after the second query, pagination is not working.

<?php

    $prop_no      =   intval( get_option('wp_estate_prop_no', '') );
    $paged        = (get_query_var('paged')) ? get_query_var('paged') : 1;

    $args = array(
            'post_type'        =>  'estate_property',
            'author'           =>  $current_user->ID,
            'paged'             => $paged,
            'posts_per_page'    => $prop_no,
            'post_status'      =>  array( 'any' ),              
        );

    $prop_selection = new WP_Query($args);

    //some code

    $args = array(
            'post_type'        =>  'estate_property',
            'author'           =>  $current_user->ID,
            'paged'             => $paged,
            'posts_per_page'    => $prop_no,
            'post__in'         =>  $sorted_posts,
            'orderby'          => 'post__in'

        );


    $prop_selection = new WP_Query($args);

?>

I tried removing the ‘paged’ parameter from one of the queries, that gives either wrong results or no pagination. ex. this query returns 28 results first time but only returns 6 results after second query. And if I remove the ‘paged’ parameter from first query and add it to second query then only one page is returned when it should return 3 pages.

Related posts

1 comment

  1. Create Function in function.php

    function sofg_pagination($max_num_pages,$paged,$page_id){
        if($max_num_pages > 1){
        echo '<div class="post-wrap pgns">';
        echo '<ul class="pagination_list">';
        echo '<li><a href="'.get_permalink($page_id).'page/1">First</a></li>';
        for($i=1; $i<= $max_num_pages; $i++){
            if($paged==$i){ 
                echo '<li class="active"><a href="'.get_permalink($page_id).'page/'.$i.'">'.$i.'</a></li>';
            }
            else{ echo '<li><a href="'.get_permalink($page_id).'page/'.$i.'">'.$i.'</a></li>'; }
        }
        echo '<li><a href="'.get_permalink($page_id).'page/'.$max_num_pages.'">Last</a></li>';
        echo '</ul></div>';
        }
    }  
    

    Get Pagination Your listing page

    Define Before loop

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $page_id = get_the_ID(); 
    

    Use After Loop

    $max_num_pages_1 = $max_num_pages->max_num_pages;
    sofg_pagination($max_num_pages_1,$paged,$page_id);
    

    enter image description here

    See pagination http://hiddenwhy.igexsolutions.com/blog/

Comments are closed.