I'm having an issue with using more than one loop in the header.php file. The issue is that all sections display the results of the final loop and not their own. Here is my code:
<div class="catagory active face">
<?php /*-- Body --*/
$args01 = array('post_type' => 'services','category' => 'face',);
$loop01 = new WP_Query( $args01 );
if ( $loop01->have_posts() ) :
while ( $loop01->have_posts() ) : $loop01->the_post();
echo '<p><a class="text-white" href="'.get_permalink().'">'.get_the_title().'</a></p>';
endwhile; wp_reset_postdata();
endif;
?>
</div>
<div class="catagory hide breast">
<?php /*-- Body --*/
$args02 = array('post_type' => 'services','category' => 'breast',);
$loop02 = new WP_Query( $args02 );
if ( $loop02->have_posts() ) :
while ( $loop02->have_posts() ) : $loop02->the_post();
echo '<p><a class="text-white" href="'.get_permalink().'">'.get_the_title().'</a></p>';
endwhile; wp_reset_postdata();
endif;
?>
</div>
<div class="catagory hide body">
<?php /*-- Body --*/
$args03 = array('post_type' => 'services','category' => 'body',);
$loop03 = new WP_Query( $args03 );
if ( $loop03->have_posts() ) :
while ( $loop03->have_posts() ) : $loop03->the_post();
echo '<p><a class="text-white" href="'.get_permalink().'">'.get_the_title().'</a></p>';
endwhile; wp_reset_postdata();
endif;
?>
</div>
Any ideas as to why the first two loops displays the third loops result? What am I missing here?
I think you should move wp_reset_postdata(); to after endif; in all loops
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With