Query Items

Use the Data API to find, filter, and retrieve items from your collections. This guide walks through building queries step by step, from simple requests to more complex.

The Data Items API uses a query builder pattern where you create a query object, refine it with filters and options, and then execute it. The basic flow is:

  1. Build the query: Use items.query() to create a query object.
  2. Refine the query: Chain methods to add filters, sorting, and pagination if necessary.
  3. Execute the query: Call find() on the query object to run the query and get results.

Simple query

The most basic query() retrieves all items from a collection and returns a query object. You can then call find() to execute the query and get results. The results object contains the queried items and metadata about the items.

This example retrieves all items from the Listings collection and logs the retrieved items:

Copy

This returns up to 50 items from the collection, sorted by creation date in descending order.

Often, you'll want to chain the find() method directly to the query builder for more concise code:

Copy

Build more complex queries

You can add filters, sorting, and pagination to refine query results by chaining methods to the query object:

Copy

See WixDataQuery for a complete list of methods you can use to build queries.

Query items with references

When your collection has reference fields that link to other collections, the referenced items aren't included in query results. However, you can use the include() method to fetch these referenced items along with your main query results.

The include() method fetches referenced items along with your main query:

Copy

For multiple references or for more advanced queries, you may need to use queryReferenced() instead of include(). This method allows you to query all referenced items for a specific item, which is useful when you need to handle many references or complex relationships.

See also

Did this help?