WordPress show only users own media

Show only attachments which user uploaded:

function users_own_attachments( $wp_query_obj ) {
	global $current_user, $pagenow;
 
	if ( $pagenow == 'upload.php' || ( $pagenow == 'admin-ajax.php' && !empty( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'query-attachments' ) ) {
		$wp_query_obj->set( 'author', $current_user->ID );
	}
}
add_action( 'pre_get_posts', 'users_own_attachments');

Leave a Reply

Your email address will not be published. Required fields are marked *