Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to reset loop? 2 loops on 1 page


  • m1000
    Participant

    @m1000

    Hi!

    There is one loop on main content with topics of one tag (archive) and second loop on the sidebar:

    if ( bbp_has_topics( array( 'author' => 0, 'order' => 'DESC', 'paged' => 1, 'posts_per_page' => $number_of_topics ) ) ) :
    		bbp_get_template_part( 'loop', 'mytopics' );

    This second loop should display all global topics but it shows the same topics like the 1st loop. How to fix it?

Viewing 7 replies - 1 through 7 (of 7 total)

  • Robin W
    Moderator

    @robin-w

    bbp_has_topics has a ‘reset’ in it, it executes

    new WP_Query( $r )
    

    what is the loop in your sidebar?


    m1000
    Participant

    @m1000

    It’s

    if ( bbp_has_topics( array( 'author' => 0, 'show_stickies' => false, 'order' => 'DESC', 'post_parent' => 'any', 'paged' => 1, 'posts_per_page' => $number_of_topics ) ) ) :
    		bbp_get_template_part( 'loop', 'mytopics' );
    	else :
    		bbp_get_template_part( 'feedback', 'no-topics' );
    	endif;

    Robin W
    Moderator

    @robin-w

    without seeing the detail, not sure what you are trying to achieve.

    I don’t think this has anything to do with resetting, rather that both queries are doing the same thing. post_parent deafulats to any in many cases.

    Try running each individually to see if they produce separate results when only one is run


    m1000
    Participant

    @m1000

    On the main content (url: forums/topic-tag/android/) is loaded content-archive-topic.php template with following code:
    <?php bbp_get_template_part( 'loop', 'topics' ); ?>

    loop-topics.php contains

    <?php while ( bbp_topics() ) : bbp_the_topic(); ?>
    
    			<?php bbp_get_template_part( 'loop', 'single-topic' ); ?>
    
    		<?php endwhile;
    		wp_reset_query();?>

    So it loads topics with android tag.

    On the sidebar I have this code

    if ( bbp_has_topics( array( 'author' => 0, 'show_stickies' => false, 'order' => 'DESC', 'post_parent' => 'any', 'paged' => 1, 'posts_per_page' => $number_of_topics ) ) ) :
    		bbp_get_template_part( 'loop', 'mytopics' );
    	else :
    		bbp_get_template_part( 'feedback', 'no-topics' );
    	endif;

    It should load all recent topics from all forums but it loads topics with android tag, and it happens when I’m on this page forums/topic-tag/android/


    Robin W
    Moderator

    @robin-w

    Interesting… WP_query has a tag parameter, lets try resetting that

    Try

    if ( bbp_has_topics( array( 'author' => 0, 'show_stickies' => false, 'order' => 'DESC', 'post_parent' => 'any', 'paged' => 1, 'posts_per_page' => $number_of_topics,  'tag' => '') ) ) :
    		bbp_get_template_part( 'loop', 'mytopics' );
    	else :
    		bbp_get_template_part( 'feedback', 'no-topics' );
    	endif;

    m1000
    Participant

    @m1000

    I added ‘tag’ => ” and it doesn’t help.


    Robin W
    Moderator

    @robin-w

    ok, sorry you’ve exhausted my knowledge 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
Skip to toolbar