Display list of uploaded images, filtered by user under a specific user group

This example loops through all photographers and then displays all images uploaded by them:

<ul>
<?php
    $photographers = get_users( 'role=photographer' );
    foreach( $photographers as $user ) :
        $pictures = new WP_Query( array( 'author' => $user->ID, 'post_type' => 'attachment', 'post_status' => 'inheret', 'posts_per_page' => -1 ) );
        echo '<li><h3>' . $user->user_nicename . '</h3>';
            if ( $pictures->posts ) :
                echo '<ul>';
                foreach ( $pictures->posts as $picture ) :
                    echo '<li>'. wp_get_attachment_image( $picture->ID ) .'</li>';              
                endforeach;
                echo '</ul>';
            endif;
        echo '</li>';
    endforeach;
?>
</ul>

It uses the get_users function to get all users that have the photographer role assigned to them. Next a new query is generated based on each photographers ID that gets all attachments.

tech