Get attachments by user

Is there a way to get attachments by user? I need a way to display all the images uploaded by a specific user. (I probably need the attachment IDs so that I can use wp_get_attachment_url to display them.)

Related posts

Leave a Reply

1 comment

  1. Use a custom query for this.

    $user_id = 1;
    $the_query = new WP_Query( array( 'post_type' => 'attachment', 'post_status' => 'inherit', 'author' => $user_id) );
    if ( $the_query->have_posts() ) while ( $the_query->have_posts() ) : $the_query->the_post();
       the_title();
    endwhile;
    

    This will show all the attachment titles for user with user id 1. You can use get_the_ID() in the loop to get the attachment ID.