Support

Account

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