1

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?

2
  • why would you - they're different things. what problems are you experiencing?
    – anu
    Commented Mar 26, 2011 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.
    – wyc
    Commented Mar 26, 2011 at 13:46

1 Answer 1

1

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".

1
  • @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).
    – wyc
    Commented Apr 8, 2011 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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