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?

  • Yes, That is exactly how I meant! Thank you. The only thing now is that I realized I will have to make a nested repeater to get several download sections with different headlines. I’m not 100% sure I know how to solve that. Can you help me? This is my code as it looks right now. The headline field is in the first repeater “file_sections”.

    $current_user = wp_get_current_user();
    
        echo '<div class="download_wrapper">';
    
            if( have_rows('file_sections', 'options_customer') ):
    
                while ( have_rows('file_sections', 'options_customer') ) : the_row();
    
                    echo '<div class="file-section">';
    
                        $download_headline = get_sub_field('download_headline', 'options_customer');
                        $download_preamble = get_sub_field('download_preamble', 'options_customer');
    
                        if ( $download_headline ) {
                            echo '<div class="file-title-section">';
                                echo '<h3>' . $download_headline . '</h3>';
                                echo '<p>' . $download_preamble . '</p>';
                            echo '</div>';
                        }
    
                        if( have_rows('section_download', 'options_customer') ):
    
                            ob_start();
                            $has_output = false;
    
                            echo '<ul class="download-list">';
    
                                while ( have_rows('section_download', 'options_customer') ) : the_row();
    
                                    //The file
                                    $file              = get_sub_field('client_file');
                                    //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 ) || empty($file_restriction) ) { 
                                       $has_output = true;
                                       
                                       echo '<li class="download-item animateUp">';
    
                                            echo '<a target="_blank" title="Ladda ner fil: ' . $file['title'] . '" alt="Ladda ner fil: ' . $file['title'] . '" href="' . $file['url'] . '"></a>';
    
                                            echo '<div class="item-wrapper">';
                                                if( $file['type'] == 'image' ):
                                                    echo '<div class="item-image">';
                                                        echo '<img src="' . $file['sizes']['thumbnail'] .'" alt="'. $file['alt'] . '" width="50" height="auto">';
                                                    echo '</div>';
                                                endif;
                                                
                                                echo '<div class="item-content">';
                                                    echo '<h3>' . $file['title'] . '</h3>';
                                                    echo '<span>' . $file['modified'] . '</span>';
                                                echo '</div>';
                                            echo '</div>';
    
                                            $hr_size = size_format( $file['filesize'] );
                                            echo '<div class="item-size">' . $hr_size .'</div>';
    
                                        echo '</li>';
                                    }
    
                                endwhile;
    
                            echo '</ul>';
    
                            $output = ob_get_clean();
                            if ($has_output) {
                                echo $output;
                            }
    
                        endif;
    
                    echo '</div>';
    
                endwhile;
    
            endif;
    
        echo '</div>';