Inside of my loop in single.php, I used a custom query using get_posts
to return posts belonging to a certain category.
<?php global $post;
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$myposts = get_posts("paged=$paged&category=5");?>
<?php foreach($myposts as $post) :?>
<?php the_title();?>
<?php endforeach; ?>
The problem is that the original loop, which is the single.php loop, seem to do not work after the execution of the query. For instance, the navigation links (next and previous) dont work.
Have you ever faced this issue? your help is appreciated.
2 Answers
You need to call wp_reset_postdata()
after your query to restore the global $post
variable that the navigation link functions use to determine the next/previous posts.