Creates a query to retrieve a list of categories.
The queryCategories()
function builds a query to retrieve a list of categories and returns a CategoriesQueryBuilder
object.
The returned object contains the query definition, which is typically used to run the query using the find()
function.
You can refine the query by chaining CategoriesQueryBuilder
functions onto the query. CategoriesQueryBuilder
functions enable you to sort, filter, and control the results queryCategories()
returns.
queryCategories()
runs with these CategoriesQueryBuilder
defaults, which you can override:
PROPERTY | SUPPORTED FILTERS & SORTING |
---|---|
_id | eq() |
name | eq() |
_createdDate | ascending() ,descending() |
function queryCategories(
options: QueryCategoriesOptions,
): CategoriesQueryBuilder;
Options to use when querying categories.
import { categories } from "wix-events.v2";
import { webMethod, Permissions } from "wix-web-module";
import { elevate } from "wix-auth";
const elevatedQueryCategories = elevate(categories.queryCategories);
export const myQueryCategoriesFunction = webMethod(
Permissions.Anyone,
async () => {
try {
const items = await elevatedQueryCategories().find();
console.log("Categories: ", items);
return items;
} catch (error) {
console.error(error);
}
},
);
/* Promise resolves to:
* {
* "_items": [
* {
* "name": "workshop-leather",
* "states": [
* "MANUAL"
* ],
* "_id": "db3e2663-4ed3-43f7-ba68-5d71611702c8",
* "_createdDate": "2024-06-20T07:12:41.366Z"
* },
* {
* "name": "Cosmic Odyssey: Exploring the Mysteries of the ...",
* "states": [
* "AUTO",
* "RECURRING_EVENT",
* "HIDDEN"
* ],
* "_id": "a03a6667-2ada-45d6-9835-834351ab995f",
* "_createdDate": "2024-04-30T10:31:56.791Z"
* },
* {
* "name": "Mindful Living Retreat: Nurturing Wellness and ...",
* "states": [
* "AUTO",
* "RECURRING_EVENT",
* "HIDDEN"
* ],
* "_id": "eebe3ed6-ffef-46e4-a83a-e883d7ad8fdd",
* "_createdDate": "2023-07-13T13:42:12.833Z"
* },
* {
* "name": "food",
* "states": [
* "MANUAL"
* ],
* "_id": "bd964127-63ff-47e0-92af-8714037de8c9",
* "_createdDate": "2023-07-12T12:40:57.129Z"
* },
* {
* "name": "technology",
* "states": [
* "MANUAL"
* ],
* "_id": "89d3e8d4-45bc-4439-9e74-7e21b3418c88",
* "_createdDate": "2023-07-12T11:07:35.776Z"
* },
* {
* "name": "science",
* "states": [
* "MANUAL"
* ],
* "_id": "4a69c13e-eb55-47a8-8ccf-9b55198428a0",
* "_createdDate": "2023-07-12T10:51:00.029Z"
* },
* {
* "name": "Professional Leather Handbag, a course by Lili ...",
* "states": [
* "AUTO",
* "RECURRING_EVENT",
* "HIDDEN"
* ],
* "_id": "9dadda33-659d-4376-a69d-19d50fad585a",
* "_createdDate": "2023-07-11T14:28:07.061Z"
* }
* ],
* "_originQuery": {
* "filterTree": {
* "$and": []
* },
* "invalidArguments": [],
* "encoder": {},
* "transformationPaths": {},
* "sort": [],
* "paging": {},
* "pagingMethod": "OFFSET",
* "builderOptions": {
* "cursorWithEmptyFilterAndSort": true
* }
* },
* "_limit": 50,
* "_totalCount": 8,
* "_offset": 0
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.