Home › Forums › General Issues › Multiple if( in array… on one page not working. › Reply To: Multiple if( in array… on one page not working.
Nope, that wasn’t it. If I take away the ACF the two WP loops work perfectly. But when I put them back only the first loop works.
New Code to be safe separating the loops
<!-- ACF Start -->
<?php if( in_array( 'Barley', get_field('ingredients') ) ) { ?>
<!-- WP Loop Start -->
<?php $BarleyQuery = new WP_Query( 'category_name=Barley&posts_per_page=1&orderby=rand' ); ?>
<?php while ( $BarleyQuery->have_posts() ) : $BarleyQuery->the_post(); ?>
<!-- Post Contents -->
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'full' ); } ?>
<!-- End Post Contents -->
<?php endwhile; ?>
<!-- WP Loop End -->
<?php }; ?>
<!-- ACF End -->
<!-- ACF Start -->
<?php if( in_array( 'Water', get_field('ingredients') ) ) { ?>
<!-- WP Loop Start -->
<?php $WaterQuery = new WP_Query( 'category_name=Water&posts_per_page=1&orderby=rand' ); ?>
<?php while ( $WaterQuery->have_posts() ) : $WaterQuery->the_post(); ?>
<!-- Post Contents -->
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'full' ); } ?>
<!-- End Post Contents -->
<?php endwhile; ?>
<!-- WP Loop End -->
<?php }; ?>
<!-- ACF End -->
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.