Home › Forums › Add-ons › Repeater Field › Acf while loop if any rows return this value once? › Reply To: Acf while loop if any rows return this value once?
The below should achieve just that:
<?php
global $post;
$author_id = $post->post_author;
$user = get_userdata( $author_id );
// Get all the user roles as an array.
$user_roles = $user->roles;
$author_roles = array('administrator', 'editor', 'contributor');
if( have_rows('section_download', 'options_customer') ):
if( array_intersect($author_roles, $user->roles ) ) :
echo '<h3>' . $download_headline . '</h3>';
endif;
echo '<ul>';
while ( have_rows('section_download', 'options_customer') ) : the_row();
//File restricted to
$file_restriction = get_sub_field('role_restriction');
//Current user group
$wcb2b_current_user_group = get_the_author_meta( 'wcb2b_group', $current_user->ID );
$restricted_file = get_sub_field('restricted_file');
$non_restricted_file = get_sub_field('non_restricted_file');
if( array_intersect($author_roles, $user->roles ) ) : ?>
<li><a href="<?php echo $restricted_file['url']; ?>"><?php echo $restricted_file['filename']; ?></a></li>
<?php endif; ?>
<li><a href="<?php echo $non_restricted_file['url']; ?>"><?php echo $non_restricted_file['filename']; ?></a></li>
<?php endwhile;
echo '</ul>';
endif;
You’ve not included all of your code! You haven’t shown the file fields being declared so made up some for the example.
Does that help?
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!
ACF wouldn’t be so widely used in WordPress if it didn’t have some pretty amazing capabilities. In this article, we look at a few of the features we’ll discuss during “7 things you didn’t know you could do with ACF” at #WPEDecode later this month. https://t.co/5lnsTxp81j pic.twitter.com/Yf0ThPG1QG
— Advanced Custom Fields (@wp_acf) March 16, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.