Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

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!

share|improve this question
1  
Whoops, forgot to reset the query after query_posts with wp_reset_query, after adding that it works now. –  Odyss3us Mar 9 '11 at 19:24
    
Well spotted though, i like how you spotted your error and corrected it(and posted it back here in the question), you've scored one in my book... ;) –  t31os Mar 9 '11 at 21:18
add comment

2 Answers 2

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!

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.