d2321
5/14/2020 - 9:50 PM

pagination wp query

<div class="container">	

<?php
if ( get_query_var('paged') ) {
    $paged = get_query_var('paged');
} elseif ( get_query_var('page') ) {
	$paged = get_query_var('page');
} else {
    $paged = 1;
}

$custom_query_args = array(
    'cat' => array(21,22), 
    'posts_per_page' => 6,
    'paged' => $paged,
); 

$custom_query = new WP_Query( $custom_query_args );

while( $custom_query->have_posts() ) : $custom_query->the_post();
?>


<div style="padding:0 5px">
	<h3><a href="<?php the_permalink() ?>" rel="bookmark"> <?php the_title(); ?></a></h3>
</div>
<?php endwhile; ?>

    <?php if ($custom_query->max_num_pages > 1) : // custom pagination  ?>
        <?php
        $orig_query = $wp_query; // fix for pagination to work
        $wp_query = $custom_query;
        ?>
<section class="secNavigation">
	<div class="container">
		<div class="row">
			<div class="col-xs-12">
				<div class="navigation">
					<?php $big = 999999999; // need an unlikely integer
						echo paginate_links(array(
						'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
						'format' => '?paged=%#%',
						'before_page_number' => '<span class="screen-reader-text">'.__(' ','textdomain').' </span>',
						'prev_next' => false
					)); ?>	
				</div>	
				
			</div>
		</div>
	</div>
</section>	
        <?php
        $wp_query = $orig_query; // fix for pagination to work
        ?>
    <?php endif; ?>
<?php wp_reset_postdata(); ?>
</div><!-- container -->