Using get_post and wrong posts showing up after initial use
-
I am using get_posts on my home page. Afterwards, I want to use normal loops to display posts. But for some reason, the get_post doesn’t seem to be getting cleared. ANy page in teh site will display what looks like the first get_posts that is being used on the page.
It is driving me batty. I have looked around and found nothing about it. The closest I coudl see was a rewind_posts function. But that is to reusea query… so that doesn’t work.
Here is an example of my code:
<?php
$posts = get_posts('numberposts=1');
foreach($posts as $post) :
setup_postdata($post);
?>
<div class="mainPost" id="post-<?php the_ID(); ?>">
<h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h1>
<small class="author">written by <span><?php the_author() ?></span> | <?php the_time('l, F j, Y') ?></small>
<div class="entry">
<?php the_excerpt('Read the rest of this entry »'); ?>
</div>
<p class="postmetadata"><span class="read"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">Read The Article</a></span> <span class="add_comments"><?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></span> <?php edit_post_link('Edit', '', ' | '); ?>
</div>
<?php endforeach; ?>
<!-- END MAIN POST -->
<?php
$posts = get_posts('numberposts=5&offset=1');
foreach($posts as $post) :
setup_postdata($post);
?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
<small class="author">written by <span><?php the_author() ?></span><?php the_time('l, F j, Y') ?></small>
<div class="entry">
<?php the_excerpt('Read the rest of this entry »'); ?>
</div>
<p class="postmetadata"><span class="read"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">Read The Article</a></span> <span class="add_comments"><?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></span> <?php edit_post_link('Edit', '', ' | '); ?>
</div>
<?php endforeach; ?>
<!-- END POSTS -->
- The topic ‘Using get_post and wrong posts showing up after initial use’ is closed to new replies.