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;
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.