I am try to put pagination in my custom post in wordpress. my custom post type name is videos. it appears the pagination but when I click on the pagination page it goes to 404 page.
<?php
$videos= new WP_Query(array(
'post_type'=>'videos',
'posts_per_page' => 9,
));?>
<?php if($videos->have_posts()) : ?>
<?php while($videos->have_posts()) : $videos->the_post(); ?>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
<div class="video">
<?php the_post_thumbnail(); ?>
<div class="watch">
<a href="<?php the_permalink(); ?>"><i class="fa fa-play"></i></a>
</div>
</div>
<div class="video-exerpt">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</div>
</div>
<?php endwhile; ?>
<div class="col-xs-12 text-center">
<?php
$GLOBALS['wp_query'] = $videos;
the_posts_pagination(
array(
'mid_size' => '2',
'prev_text' => '<i class="fa fa-hand-o-left"></i> Previous',
'next_text' => 'Next <i class="fa fa-hand-o-right"></i>',
'screen_reader_text' => ' '
)
);
?>
</div>
<?php else :?>
<h3><?php _e('404 Error: Not Found', 'Bangladesh Parjatan'); ?></h3>
<?php endif; ?>
<?php wp_reset_postdata();?>
its shows the pagination bt the links are not working. Please help me.
pass your wp_query arguments like this. You should use paged argument for pagination.
hopfully your pagination will work fine.
Can you please replace below code?
Try the following code: