[Resolved] Bug? (Multiple Loops in Page gives wrong info)
If you read my previous post you’ll remember that I was working on a static front page, displaying some posts.
This is the first part of the code:
<?php if ( have_posts() ) : the_post(); ?><h2><?php the_title(); ?></h2><?php the_content(); else: ?>Someone Broke the About Page<?php endif; ?>
That works perfectly fine! Now I do this
<?php $posts = get_posts( 'numberposts=2' ); foreach ($posts as $post) : setup_postdata($post); ?> <h3> <a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a> </h3> <h4> Posted <?php the_date() ?> - Comments (<?php comments_number(); ?>) </h4> <?php the_excerpt(); ?> <?php endforeach; ?>
And while the dates, comment count, excerpt all work perfectly, the_ID never echos, the_title always gives me the title of the Page, not the post, and same for the permalink.
Right now I have circumvented this issue by accessing properties of the $post object directly (guid, post_title, and ID) but I believe if I do it like so, plugins won’t be able to hook onto it because I’m not calling the hook, correct?
So what am I doing wrong? Or is this a bug? Is there a better workaround?
- The topic ‘[Resolved] Bug? (Multiple Loops in Page gives wrong info)’ is closed to new replies.