Support

Account

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?