Class: Query

wp.media.model. Query


new Query( [models] [, options])

wp.media.model.Query A collection of attachments that match the supplied query arguments. Note: Do NOT change this.args after the query has been initialized. Things will break.
Parameters:
Name Type Argument Description
models array <optional>
Models to initialize with the collection.
options object <optional>
Options hash.
Properties
Name Type Argument Description
args object <optional>
Attachments query arguments.
Properties
Name Type Argument Description
posts_per_page object <optional>
Source:

Extends

Members


<static, readonly> defaultArgs

Source:

<static, readonly> defaultProps

Source:

<static, readonly> orderby

Source:

<static, readonly> propmap

A map of JavaScript query properties to their WP_Query equivalents.
Source:

model :wp.media.model.Attachment

Type:
Inherited From:
Source:

Methods


<static> get( [props] [, options])

Creates and returns an Attachments Query collection given the properties. Caches query objects and reuses where possible.
Parameters:
Name Type Argument Description
props object <optional>
Properties
Name Type Argument Default Description
cache Object <optional>
true Whether to use the query cache or not.
order Object <optional>
orderby Object <optional>
include Object <optional>
exclude Object <optional>
s Object <optional>
post_mime_type Object <optional>
posts_per_page Object <optional>
menu_order Object <optional>
post_parent Object <optional>
post_status Object <optional>
author Object <optional>
options Object <optional>
Source:
Returns:
A new Attachments Query collection.
Type
wp.media.model.Query

<private> _changeFilteredProps(model)

Parameters:
Name Type Description
model Backbone.Model
Inherited From:
Source:

<private> _changeOrder()

Sort the collection when the order attribute changes.
Inherited From:
Source:

<private> _changeOrderby(model, orderby)

Set the default comparator only when the `orderby` property is set.
Parameters:
Name Type Description
model Backbone.Model
orderby string
Inherited From:
Source:

<private> _changeQuery(model, query)

If the `query` property is set to true, query the server using the `props` values, and sync the results to this collection.
Parameters:
Name Type Description
model Backbone.Model
query Boolean
Inherited From:
Source:

<private> _requery()

If the collection is a query, create and mirror an Attachments Query collection.
Inherited From:
Source:

<private> _validateAllHandler(attachments, options)

Parameters:
Name Type Description
attachments wp.media.model.Attachments
options Object
Inherited From:
Source:
Returns:
Returns itself to allow chaining.
Type
wp.media.model.Attachments

<private> _validateHandler(attachment, attachments, options)

Parameters:
Name Type Description
attachment wp.media.model.Attachments
attachments wp.media.model.Attachments
options Object
Inherited From:
Source:
Returns:
Returns itself to allow chaining.
Type
wp.media.model.Attachments

hasMore()

Whether there are more attachments that haven't been sync'd from the server that match the collection's query.
Overrides:
Source:
Returns:
Type
boolean

initialize( [models] [, options])

Parameters:
Name Type Argument Default Description
models array <optional>
[] Array of initial models to populate the collection.
options object <optional>
{}
Overrides:
Source:

mirror(The)

Start mirroring another attachments collection, clearing out any models already in the collection.
Parameters:
Name Type Description
The wp.media.model.Attachments attachments collection to mirror.
Inherited From:
Source:
Returns:
Returns itself to allow chaining.
Type
wp.media.model.Attachments

more( [options])

Fetch more attachments from the server for the collection.
Parameters:
Name Type Argument Default Description
options object <optional>
{}
Overrides:
Source:
Returns:
Type
Promise

observe(The)

Start observing another attachments collection change events and replicate them on this collection.
Parameters:
Name Type Description
The wp.media.model.Attachments attachments collection to observe.
Inherited From:
Source:
Returns:
Returns itself to allow chaining.
Type
wp.media.model.Attachments

parse(resp, xhr)

A custom AJAX-response parser. See trac ticket #24753
Parameters:
Name Type Description
resp Object | Array The raw response Object/Array.
xhr Object
Inherited From:
Source:
Returns:
The array of model attributes to be added to the collection
Type
Array

saveMenuOrder()

If this collection is sorted by `menuOrder`, recalculates and saves the menu order to the database.
Inherited From:
Source:
Returns:
Type
undefined | Promise

sync(method, model [, options])

Overrides Backbone.Collection.sync Overrides wp.media.model.Attachments.sync
Parameters:
Name Type Argument Default Description
method String
model Backbone.Model
options Object <optional>
{}
Source:
Returns:
Type
Promise

unmirror()

Stop mirroring another attachments collection.
Inherited From:
Source:

unobserve(The)

Stop replicating collection change events from another attachments collection.
Parameters:
Name Type Description
The wp.media.model.Attachments attachments collection to stop observing.
Inherited From:
Source:
Returns:
Returns itself to allow chaining.
Type
wp.media.model.Attachments

validate(attachment, options)

Add or remove an attachment to the collection depending on its validity.
Parameters:
Name Type Description
attachment wp.media.model.Attachment
options Object
Inherited From:
Source:
Returns:
Returns itself to allow chaining.
Type
wp.media.model.Attachments

validateAll(attachments [, options])

Add or remove all attachments from another collection depending on each one's validity.
Parameters:
Name Type Argument Default Description
attachments wp.media.model.Attachments
options object <optional>
{}
Inherited From:
Source:
Fires:
  • wp.media.model.Attachments#event:reset
Returns:
Returns itself to allow chaining.
Type
wp.media.model.Attachments

validator(attachment)

Checks whether an attachment is valid.
Parameters:
Name Type Description
attachment wp.media.model.Attachment
Inherited From:
Source:
Returns:
Type
Boolean