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.

This is the code:

            <?php get_template_part( 'pagination', 'bbp_replies' ); ?>

            <?php query_posts('gdsr_sort=thumbs&post_type=bbp_reply&posts_per_page=2'); ?>
            <?php while ( have_posts() ) : the_post(); ?>
                <h2><?php  the_title(); ?></h2>
                <?php the_content(); ?>
            <?php endwhile; ?>
            <?php wp_reset_query(); ?>

            <?php while ( bbp_replies() ) : bbp_the_reply(); ?>

                <div class="topic-entry">

                    <div class="topic-author">
                        <?php bbp_reply_author_link( array( 'type' => 'avatar' ) ); ?>
                        <?php bbp_reply_author_link( array( 'type' => 'name' ) ); ?>
                        <?php printf( __( '%1$s', 'bbpress' ), get_the_date() ); ?>
                    </div>

                    <div class="topic-content">
                        <?php bbp_reply_content(); ?>
                        <span class="like-counter"><?php DisplayVotes(get_the_ID()); ?></span>
                    </div>

                        <?php bbp_reply_admin_links(); ?>

                    </div>

The first query_posts loop list the 2 most voted replies. The second bbPress loop list all other replies in DESC order.

Will I encounter bugs if I have these two loops in a same file template?

share|improve this question
    
why would you - they're different things. what problems are you experiencing? –  anu Mar 26 '11 at 9:33
    
@anu I'm not very sure, but I think they are both Main Loops. Having two main loops in a single file is dangerous. –  janoChen Mar 26 '11 at 13:46
add comment

1 Answer

up vote 1 down vote accepted

I would not do it this way, but it should not be a problem. When your template file is executed the "real main loop" already contains the posts for this page. You then execute query_posts() to do a second query, which "hides" the "real" loop, but after you are done you execute wp_reset_query() which makes the "real" loop again the active loop.

It would get confusing and lead to errors if you would embed the two loops, thus if you executed another query_posts() in that main where loop. Then you must use get_posts() or a direct WP_Query to prevent errors.

Personally, I never call query_posts() myself and always use get_posts(), because it doesn't change any global variables "behind my back".

share|improve this answer
    
@Jan Fabry I always use WP_Query too, but here I'm trapped. The GD rating plugin only works with query_posts(); and some elements from the bbPress plugins don't show up with WP_Query (and there aren't any other plugins which have the features I need). –  janoChen Apr 8 '11 at 14:37
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.