> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt ## Resource: Query Items ## Article: Query Items ## Article Link: https://dev.wix.com/docs/develop-websites-sdk/code-your-site/work-with-data/data-api/query-items.md ## Article Content: # 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()`](https://dev.wix.com/docs/sdk/backend-modules/data/items/query.md) retrieves all items from a collection and returns a query object. You can then call [`find()`](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-query/find.md) 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: ```javascript import { items } from "@wix/data"; // Get all items from the Listings collection const listingsQuery = items.query("Listings"); const listingResults = await listingsQuery.find(); console.log("Listings:", listingResults.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: ```javascript import { items } from "@wix/data"; // Get all items from the Listings collection const listingResults = await items.query("Listings").find(); console.log("Listings:", listingResults.items); ``` ## Build more complex queries You can add filters, sorting, and pagination to refine query results by chaining methods to the query object: ```javascript import { items } from "@wix/data"; // Build a complex query step by step const listings = items .query("Listings") .gte("bedrooms", 2) // Filter: 2 or more bedrooms .ascending("price") // Sort: by price ascending .limit(20) // Limit: return 20 items max .find(); console.log("Listings:", results.items); ``` See [WixDataQuery](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-query/introduction.md) 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()`](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-query/include.md) method to fetch these referenced items along with your main query results. The `include()` method fetches referenced items along with your main query: ```javascript import { items } from "@wix/data"; // Query listings and include agent information const results = await items .query("Listings") .include("agent") // Include referenced listing agent .find(); // Access referenced data results.items.forEach((listing) => { console.log(`Listing: ${listing.title}`); console.log(`Agent: ${listing.agent.name}`); // Referenced agent data }); ``` For multiple references or for more advanced queries, you may need to use [`queryReferenced()`](https://dev.wix.com/docs/sdk/backend-modules/data/items/query-referenced.md) instead of [`include()`](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-query/include.md). 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 - [Data Items API](https://dev.wix.com/docs/sdk/backend-modules/data/items/introduction.md)