Support

Account

Home Forums General Issues Relationship not reseting main loop

Helping

Relationship not reseting main loop

  • Hello
    Im having problem with reseting main loop with <?php wp_reset_postdata(); ?>

    I have two relationship call, then main loop.
    My code looks like:

    <?php 
                              $posts = get_field('porady');
                              if( $posts ): ?>
                                  <?php foreach( $posts as $post): ?>
                                      <?php setup_postdata($post); ?>
                                      <li><a href="<?php the_permalink();?>"><?php the_title();?></a></li>
                                  <?php endforeach; ?>
                                  <?php wp_reset_postdata(); ?>
                              <?php endif; ?> 
    
    <?php 
                              $posts = get_field('najpopularniejsze_tematy');
                              if( $posts ): ?>
                                  <?php foreach( $posts as $post):?>
                                      <?php setup_postdata($post); ?>
                                      <li><a href="<?php the_permalink();?>"><?php the_title();?></a></li>
                                  <?php endforeach; ?>
                                  <?php wp_reset_postdata(); ?>
                              <?php endif; ?>   
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>                     
                  <?php the_content();?>      
                  <?php endwhile; else: ?><?php endif; ?><?php wp_reset_query();?>     
    

    Problem is that main loop is taking first post from second relationship. Any advice?

  • Hmm strange – if I change name from $posts to unique and different names for each of relationship calls (eg. $posts_a, $posts_b) – it works. Any idea why ?

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.