[wp-trac] [WordPress Trac] #63668: Media / REST API: Support specifying multiple media types or mime types when listing media

WordPress Trac noreply at wordpress.org
Mon Jul 7 06:57:05 UTC 2025


#63668: Media / REST API: Support specifying multiple media types or mime types
when listing media
-------------------------+-----------------------------
 Reporter:  talldanwp    |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  REST API     |    Version:  4.7
 Severity:  normal       |   Keywords:
  Focuses:  rest-api     |
-------------------------+-----------------------------
 Currently the REST API's media endpoint has a limitation that a user can
 only specify one media type or mime type to filter the results when
 listing media.

 See https://developer.wordpress.org/rest-api/reference/media/#arguments.

 It'd be useful though if a user of the API could specify more than one of
 'image', 'video', 'audio' as an example to get a mixed collection of
 results.

 An example use case for this - the block editor's inserter has a media
 tab, and at the bottom of that tab there's an 'Open Media Library' button
 that shows a media modal with images, video and audio all at once.
 Currently it wouldn't be possible to create a REST API driven version of
 this UI without using filters to change how the REST API works.

 ----

 **Implementation**

 I had a look into how this might be implemented. The REST controller for
 attachments (media) expands the media type into a `post_mime_type` query
 param for WP_Query:
 https://github.com/WordPress/wordpress-
 develop/blob/7170a0b91e082c80e0f287f9e61683f359a2619f/src/wp-includes
 /rest-api/endpoints/class-wp-rest-attachments-controller.php#L87-L96

 WP_Query uses the `wp_post_mime_type_where` function to handle this param,
 and the definition shows it can handle multiple mime type:
 https://github.com/WordPress/wordpress-
 develop/blob/7170a0b91e082c80e0f287f9e61683f359a2619f/src/wp-
 includes/post.php#L3663-L3709

 When a user specifies a single media_type currently, this is often
 expanded into multiple mime types - image will support image/jpeg,
 image/png etc, so I don't think adding the functionality would be a
 technically difficult, but I appreciate feedback on anything I might have
 missed.

 A question for me is whether using the existing `media_type` option for
 this purpose is ok.

 It may also be good to consider whether multiple `mime_type`s can also be
 supported at the same time.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63668>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list