[wp-trac] [WordPress Trac] #64046: Attachments REST API: Add support for filtering attachments by multiple media types

WordPress Trac noreply at wordpress.org
Tue Sep 30 01:29:17 UTC 2025


#64046: Attachments REST API: Add support for filtering attachments by multiple
media types
--------------------------------------+------------------------------
 Reporter:  ramonopoly                |       Owner:  (none)
     Type:  enhancement               |      Status:  new
 Priority:  normal                    |   Milestone:  Awaiting Review
Component:  REST API                  |     Version:  trunk
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:  rest-api
--------------------------------------+------------------------------
Description changed by ramonopoly:

Old description:

> The [https://github.com/WordPress/wordpress-develop/blob/6.8.2/src/wp-
> includes/rest-api/endpoints/class-wp-rest-attachments-controller.php#L88
> WP REST Attachments Controller] permits filtering by "media_type" in the
> query args.
>
> A "media type" might be "image" or "video" or "audio".
>
> But you can only filter by one type at a time.
>
> What if I wanted all my audio and video files in the response.
>
> Attachments Controller says no.
>
> But if there were a "media_types" parameter, users could filter
> attachment queries by an array of media types.
>
> Luckily post_mime_type already supports an array of strings.
>
> https://github.com/WordPress/wordpress-
> develop/blob/2446d399945bb6b8378b49c1c5b66197c323f0e3/src/wp-includes
> /class-wp-query.php#L2468
>

> {{{
> wp_post_mime_type_where
> }}}
>

> https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-
> includes/post.php#L3676

New description:

 The [https://github.com/WordPress/wordpress-develop/blob/6.8.2/src/wp-
 includes/rest-api/endpoints/class-wp-rest-attachments-controller.php#L88
 WP REST Attachments Controller] permits filtering by "media_type" in the
 query args.

 A "media type" might be "image" or "video" or "audio".

 But you can only filter by one type at a time.

 What if I wanted all my audio and video files in the response.

 Attachments Controller says no.

 But if the "media_type" parameter also accepted an array of media types,
 users could filter attachment queries by more than one media types.

 Luckily post_mime_type already supports an array of strings.

 https://github.com/WordPress/wordpress-
 develop/blob/2446d399945bb6b8378b49c1c5b66197c323f0e3/src/wp-includes
 /class-wp-query.php#L2468


 {{{
 wp_post_mime_type_where
 }}}


 https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-
 includes/post.php#L3676

--

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/64046#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list