Home › Forums › Add-ons › Repeater Field › Querying all repeater fields on a page › Reply To: Querying all repeater fields on a page
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;
}
}
?>
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.