After trying to ask help from others, I got my solution and here I am sharing that below. First there is no use of 'in_same_cat' => false,
in upper code and second get_next_post(true);
, get_previous_post(true);
is used to show next/prev post from current post categories but if you want to show all posts in next/prev then you have to use only get_next_post();
, get_previous_post();
instead of upper one. Finally the working code is shared below.
<!-- Pagination -->
<div id="post_pagination">
<?php $nextPost = get_next_post();
if($nextPost) {
$args = array(
'posts_per_page' => 1,
'include' => $nextPost->ID
);
$nextPost = get_posts($args);
foreach ($nextPost as $post) {
setup_postdata($post);
?>
<a href="https://wordpress.stackexchange.com/questions/169189/<?php the_permalink(); ?>"><div class="post_next_post">
<?php the_post_thumbnail('thumbnail'); ?>
<span class="next">Next Story »</span>
<h4><?php the_title(); ?></h4>
</div></a>
<?php
wp_reset_postdata();
} //end foreach
} // end if
?>
<?php $prevPost = get_previous_post();
if($prevPost) {
$args = array(
'posts_per_page' => 1,
'include' => $prevPost->ID
);
$prevPost = get_posts($args);
foreach ($prevPost as $post) {
setup_postdata($post);
?>
<a href="https://wordpress.stackexchange.com/questions/169189/<?php the_permalink(); ?>"><div class="post_prev_post">
<?php the_post_thumbnail('thumbnail'); ?>
<span class="prev">« Previous Story</span>
<h4><?php the_title(); ?></h4>
</div></a>
<?php
wp_reset_postdata();
} //end foreach
} // end if
?>
</div>
<!-- Pagination -->