
Okay managed to do it – but is there a way I can just output the Title + Files only if the range has products with files uploaded?
Have the following – but it will still display Range (category/taxonomy) title even if non of the products in it have a brochure uploaded to them.
<?php
$custom_terms = get_terms('range');
foreach($custom_terms as $custom_term) {
wp_reset_query();
$args = array('post_type' => 'product',
'tax_query' => array(
array(
'taxonomy' => 'range',
'field' => 'slug',
'terms' => $custom_term->slug,
),
),
);
$loop = new WP_Query($args);
if($loop->have_posts()) {
echo '<h2>'.$custom_term->name.'</h2>';
while($loop->have_posts()) : $loop->the_post();
if( have_rows('brochure') ):
echo '<h6><a href="'.get_permalink().'">'.get_the_title().'</a></h6>';
echo '<ul>';
while( have_rows('brochure') ): the_row();
$name = get_sub_field('brochure-name');
$file = get_sub_field('brochure-file');
echo '<li>';
if( $file ):
echo '<a href="'.$file.'">';
endif;
echo $name;
if( $file ):
echo '</a>';
endif;
echo '</li>';
endwhile;
echo '</ul>';
endif;
endwhile;
}
}
?>