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 think I understand the question.

    You want to show the entire thing, including the header, if any of the lines in the repeater are for the user.

    I would use a PHP output buffer like this

    
    ob_start();
    $has_output = false;
      
    echo '<h3>' . $download_headline . '</h3>';
    
    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 ) ) { 
           $has_output = true;
           // generate content
        }
    
    endwhile;
    
    $output = ob_get_clean();
    if ($has_output) {
      echo $output;
    }