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?

  • I assume you would be logged in to view this, allowing the correct user role to be allocated.

    Therefore, why don’t you check the user role outside of the repeater?

    Something like:

    <?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( array_intersect($author_roles, $user->roles ) ) :
    	echo '<h3>' . $download_headline . '</h3>';
    endif;
    
    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 );
    
    	if( in_array($wcb2b_current_user_group, $file_restriction ) ) { 
    
    	}
    
    endwhile;