I have a list of Recent Posts in the sidebar of a WordPress blog. The title and author show up properly, but the excerpt that gets shown is the excerpt of the current page/post not the relevant recent post.
The code:
<?php $myposts = get_posts('numberposts=10&offset=0');
foreach($myposts as $post) :?>
<li><a href="<?php the_permalink(); ?>"><?php the_title();?> <span>by <?php the_author(); ?></span></a> <br /> <?php the_excerpt(); ?></li>
<?php endforeach; ?>
Any idea why it would be pulling the correct Title/Author, but incorrect excerpt?
Postdata isn’t set up. Those functions pull the global values besides $post (e.g. $ID).
setup_postdata()
sets all the right values. Also, I’d suggest reseting the query after this.