acf relationship loop load different templates depending on checkbox value
<?php
$posts = get_field('accessories');
if( $posts ): ?>
<?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>
<!--start looping-->
<?php $galleryitemtype = get_sub_field('accessories_type');
if ( 'cleanout' === $galleryitemtype ) : ?>
<!--Cleanout item-->
<?php get_template_part( 'template-parts/content', 'accessoriesgallery-cleanout' ); ?>
<?php elseif
( 'control' === $galleryitemtype ) : ?>
<!--Control Packages item-->
<?php get_template_part( 'template-parts/content', 'accessoriesgallery-control' ); ?>
<?php elseif
( 'flow' === $galleryitemtype ) : ?>
<!--Flow Control item-->
<?php get_template_part( 'template-parts/content', 'accessoriesgallery-flow' ); ?>
<?php elseif
( 'heatingcooling' === $galleryitemtype ) : ?>
<!--Heating and Cooling item-->
<?php get_template_part( 'template-parts/content', 'accessoriesgallery-heating' ); ?>
<?php elseif
( 'loadin' === $galleryitemtype ) : ?>
<!--Loadin Hoppers item-->
<?php get_template_part( 'template-parts/content', 'accessoriesgallery-loadin' ); ?>
<!--end looping-->
<?php endforeach; ?>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>