Multiple loops on the same page removing post tags

I am trying to use two loops on my page, one to get the current page’s content and so on, and another to get all of the posts of a specific category.

When I do that, all of the tags for the current page disappears.

Read More

Here is my code,

Loop one:

<?php if (have_posts()) : ?>
   <?php while (have_posts()) : the_post(); ?>
      <div class="content_wrapper"><?php the_content(); ?></div>
   <?php endwhile; ?>
<?php endif; ?>

Loop two:

<?php query_posts(array('category_name' => 'test')); ?>
<?php if (have_posts()) : ?>
   <?php while (have_posts()) : the_post(); ?>
      <div><?php the_excerpt(); ?></div>
   <?php endwhile; ?>
<?php endif; ?>

Any ideas?

Thanx in advance!

Related posts

Leave a Reply

2 comments

  1. Sorry guys, stupid mistake, I forgot to reset the second loop using wp_reset_query, here is the working code,

    <?php query_posts(array('category_name' => 'test')); ?>
    <?php if (have_posts()) : ?>
        <?php while (have_posts()) : the_post(); ?>
            <div><?php the_excerpt(); ?></div>
        <?php endwhile; ?>
    <?php endif; ?>
    <?php wp_reset_query(); ?>
    

    Thanx anyways though!

  2. Odyss3us, I have read a lot about multiple queries lately and it seems there is a lot of bad practice floating around about the best way to include multiple loops in a single page. Take a look at this for reference on why you should be using WP_Query instead of query_posts. There is less risk of causing havoc using WP_Query, which query_post calls anyway. Hope this sheds some light for other readers as well.

    WP_Query Functions