WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am planning to create a "Photography" page in my wordpress site. In that page, there will be a list of the photographers (maybe create a user group called 'photographers') and display the images they have uploaded, next or under their avatar. The list of the images uploaded has to be updated automatically when they upload a new one.

Since i am new to wordpress, i am looking for any ideas that would point me to the right direction implementing the function described above. Thanks in advance.

share|improve this question
up vote 0 down vote accepted

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

    $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>';              
                echo '</ul>';
        echo '</li>';

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.