[resolved] Multiple Loop Not resetting (4 posts)

  1. mvlaver
    Posted 6 years ago #

    Hi guys hope you can help with this.

    I have two loops in my sidebar to show latest newsletter and latest podcast.

    This is the first one

    <?php $latestnewsletters = new WP_query('showposts=1&category=5'); ?>
    	<?php while ($latestnewsletters->have_posts()) : $latestnewsletters->the_post(); ?>
    		<li class="newsletter"><a href="<?php echo get_post_meta($post->ID, 'newsletter_pdf', true ); ?>">Newsletter from <?php the_title(); ?></a></li>
    	<?php endwhile; ?>

    Which is followed directly by

    <?php $latestpodcast = new WP_query('showposts=1&category=3'); ?>
    	<?php while ($latestpodcast->have_posts()) : $latestpodcast->the_post(); ?>
    		<li class="podcast"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    	<?php endwhile; ?>

    The problem is that the second loop is showing the results of the first one. i.e. the_title of the second one is showing me a title from the first one.

    Anybody know what I am doing wrong. Thanks

  2. Michael
    Forum Moderator
    Posted 6 years ago #

    try to use <?php wp_reset_query(); ?> after each loop.

  3. mvlaver
    Posted 6 years ago #

    Didn't help I'm afraid. Any other suggestions?

  4. mvlaver
    Posted 6 years ago #

    All right I'm just being an idiot sorry to waste your time. It's because there isn't such a parameter as 'category'. It should be 'cat'. Which means both queries were just giving me the same result from the pages initial query - rahr!

    Oh well hope this helps someone.

Topic Closed

This topic has been closed to new replies.

About this Topic