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:
items.query() to create a query object.find() on the query object to run the query and get results.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:
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:
You can add filters, sorting, and pagination to refine query results by chaining methods to the query object:
See WixDataQuery for a complete list of methods you can use to build queries.
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:
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.