[wp-trac] [WordPress Trac] #64467: Grid view displays attachments in the wrong order when an order query var is present but not normalized

WordPress Trac noreply at wordpress.org
Thu Jan 8 10:55:51 UTC 2026


#64467: Grid view displays attachments in the wrong order when an order query var
is present but not normalized
-------------------------------------+-------------------------------------
 Reporter:  trivedikavit             |       Owner:  (none)
     Type:  defect (bug)             |      Status:  new
 Priority:  normal                   |   Milestone:  7.0
Component:  Media                    |     Version:
 Severity:  minor                    |  Resolution:
 Keywords:  has-screenshots          |     Focuses:  javascript,
  changes-requested has-patch has-   |  administration
  unit-tests                         |
-------------------------------------+-------------------------------------

Comment (by trivedikavit):

 @adamsilverstein

 You mentioned this in the Github PR:

 > can this use options.props.order = defaults.order.toUpperCase(); like
 the original code in query.js that you remove below?

 ----

 We cannot normalize `order` directly on `defaults` (e.g.,
 `defaults.order.toUpperCase()`) in the `Attachments` model, as `defaults`
 refers to `Query.defaultProps`, which is scoped to the `Query` class and
 unavailable in the base `Attachments` class.

 **References:**
 - `defaultProps` defined in `Query`: (https://github.com/WordPress
 /wordpress-
 develop/blob/cd616cf406d77a5eb653aa97cc5b6e2dc3e669a6/src/js/media/models/query.js#L166-L169)
 - `defaults` applied using `Query.defaultProps`:
 (https://github.com/WordPress/wordpress-
 develop/blob/cd616cf406d77a5eb653aa97cc5b6e2dc3e669a6/src/js/media/models/query.js#L244)

 Attempting `defaults.order.toUpperCase()` in `Attachments.initialize()`
 would fail, as `defaults` is `undefined` in that scope.

 ==== Behavior in `Attachments` Instances

 `Attachments` is the base Backbone collection for media attachments. On
 instantiation (e.g., `new wp.media.model.Attachments(models, options)`),
 `initialize`:
 - Sets up `this.props` with `options.props`.
 - If `options.props.order` is a string, normalizes it: uppercases and
 defaults to `'DESC'` if invalid.
 - Ensures consistent `order` for sorting/filtering, handling case and
 invalid inputs.

 Previously, without normalization in `Attachments.initialize()`, plain
 `Attachments` instances (non-`Query` subclasses) could use unnormalized
 `order` (e.g., `'desc'` or `'pizza'`), causing inconsistent media library
 grid sorting.

 ==== Impact on `Query` Instances

 `Query` inherits from `Attachments`, so normalization is inherited.

 - **Before**: Normalization in `Query.get()` ensured valid `order` for
 `Query` instances.
 - **After**: Normalization in `Attachments.initialize()` during
 instantiation (via inheritance). `Query.get()` applies defaults first,
 then `new Query()` triggers normalization.
 - No change in `Query` behavior; the fix prevents bugs in other
 `Attachments` subclasses or direct usage.

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


More information about the wp-trac mailing list