Vin_fugen
Vin_fugen

Reputation: 581

Wordpress pagination causing WP_Query conflict

I'm using below code to display custom post type posts under template and sidebar plugin

<div class="side-peoptit">
      <?php $i = 1; ?>
      <?php $loop = new WP_Query(
                array(
                    'post_type' => 'people', 
                    'order' => 'ASC', 
                    'orderby' => 'meta_value',  
                    'meta_key' => 'wpcf-people-sort-order',
                    'posts_per_page' => 4, 
                    'paged' => get_query_var('paged') ? get_query_var('paged') : 1 
                    )
        ); ?>
        <?php if ($loop->have_posts()) : while ($loop->have_posts()) : $loop->the_post(); ?>
           <?php $postid = get_the_ID(); ?>
           <?php $permalink = get_permalink( $postid ); ?>             
            <div class="sbrpeop-title"><?php echo $i; ?>. <a href="<?php echo $permalink; ?>"><?PHP the_title(); ?></a> - <?php echo esc_html( get_post_meta( $postid, 'wpcf-people-designation', true ) ); ?> </div>
            <?php $i++; ?>
        <?php endwhile; endif; wp_reset_query(); ?>
    </div>

And below code i'm using in template for pagination,

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

If i access website.com/people custom posts are appearing proper in both template and sidebar. But if i access second page i,e,. website.com/people/page/2 my sidebar is showing empty.

Did anyone know where i'm going wrong ?

Upvotes: 0

Views: 421

Answers (0)

Related Questions