I have created a custom post type named movies and I want to show just this post type on my index and limit the posts per page by the number of 5. The index works correct but when I use echo paginate_links it prints page number but with wrong page URL. for example it should be site.com/?post_type=movies&paged=2 but it is site.com/?paged=2
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args= array('post_type' => array('movies'),
'paged'=>$paged);
$the_query = new WP_Query( $args );
// loop for all posts ( main page )
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post(); ?>
<div class="post-wrapper">
<div class="post-inner-wrapper">
<div class="post-title">
<span class="title">
<?php echo get_the_title() ?>
</span>
</div>
<div class="post-content">
<div class="post-outer-text">
<span class="post-inner-text">
<?php echo get_the_content(''); ?>
</span>
</div>
</div>
</div>
<div class="post-image">
<?php the_post_thumbnail(); ?>
</div>
<div class="post-details">
<span class="calendar">
<i class="fa fa-calendar" aria-hidden="true"></i>
<span class="calendar_text">
<?php the_date(); ?>
</span>
</span>
<span class="author">
<i class="fa fa-user" aria-hidden="true"></i><?php the_author(); ?>
</span>
<span class="view">
<i class="fa fa-eye" aria-hidden="true"></i><?php echo get_post_view(get_the_ID()); ?>
</span>
<span class="like">
<i class="fa fa-thumbs-o-up" aria-hidden="true"></i>256
</span>
<span class="more">
<a href="<?php the_permalink()?>">ادامه مطلب</a>
</span>
</div>
</div>
<?php
}?>
<div class="pagination">
<?php global $wp_query;
echo ($wp_query->max_num_pages);
$big = 999999999; // need an unlikely integer
$page = get_query_var('paged');
$page = (!empty($page) ? $page : 1);
// query_posts( 'category_name=category&showposts=2&paged='.$page);
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?p=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );?>
</div>
<?php
/* Restore original Post Data */
wp_reset_postdata();
}
else {
// no posts found
}