Support

Account

Forum Replies Created

  • oh, I just realized I could actually fetch that headline from the nested repeater. Works exactly as I wanted it to now! Thank you so much.

  • 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>';
  • Yes but that’s not what I’m trying to do. I’m trying to see if there are any files restricted to my user role in the loop. nevermind if they are logged in or not. (of course, they are, but that is not the point.)

  • Sorry, but no. In what way is

    if( array_intersect($author_roles, $user->roles ) ) :

    looking for the restricted role on the files?

  • If I’m able to view 5 files depending on my user role below the headline “Instructions” I will see that specific headline. If I’m not allowed to see any of the instructions-files depending on my user role, I shouldn’t see the headline either.

  • I understand what you are saying. But the headline should not be visible depending on the user role alone, but insted if there are any files in the loop connected to the user role. You understand?

  • That’s not the problem or the question. The problem is that I want to check my loop for files that are restricted to some user roles. If there aren’t any files to my user role, I shouldn’t see the headline. I can still see other files and access the page.

Viewing 7 posts - 1 through 7 (of 7 total)