> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> 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`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# Method name: queryCategories(options: QueryCategoriesOptions)

# Method package: wixBlogBackend

# Method menu location: wixBlogBackend --> categories --> queryCategories

# Method Link: https://dev.wix.com/docs/velo/apis/wix-blog-backend/categories/query-categories.md

# Method Description:

Creates a query to retrieve a list of categories. 


The Query Categories method builds a query to retrieve a list of up to 100 categories per language, and returns a [`CategoriesQueryBuilder`](https://dev.wix.com/docs/sdk/backend-modules/blog/categories/categories-query-builder/ascending.md) object. 

The response contains the query definition, which is typically used to run the query using the [`find()`](https://dev.wix.com/docs/sdk/backend-modules/blog/categories/categories-query-builder/find.md) method. 

You can refine the query by chaining `CategoriesQueryBuilder` methods to the query. `CategoriesQueryBuilder` methods enable you to sort, filter, and control the results that Query Categories returns. Any methods chained to the Query Categories method are applied in the order that they are called.

Query Categories runs with these `CategoriesQueryBuilder` defaults, which you can override. 
- [`limit(100)`](https://dev.wix.com/docs/sdk/backend-modules/blog/categories/categories-query-builder/limit.md)
- [`ascending(displayPosition)`](https://dev.wix.com/docs/sdk/backend-modules/blog/categories/categories-query-builder/ascending.md)

The following `CategoriesQueryBuilder` methods are supported for Query Categories. For a full description of the `Categories` object, see the response for the [`items`](https://dev.wix.com/docs/sdk/backend-modules/blog/categories/categories-query-result/items.md) property in [`CategoriesQueryResult`](https://www.wix.com/velo/reference/wix-blog-backend/categories/categoriesqueryresult).


|PROPERTY	|SUPPORTED FILTERS & SORTING	
|:---:|:---:|
|`_id`|[`eq()`](/categories-query-builder/eq),[`ne()`](/categories-query-builder/ne),[`in()`](/categories-query-builder/in)|
|`label`|[`eq()`](/categories-query-builder/eq),[`ne()`](/categories-query-builder/ne),[`startsWith()`](/categories-query-builder/starts-with),[`exists()`](/categories-query-builder/exists),[`in()`](/categories-query-builder/in),[`ascending()`](/categories-query-builder/ascending),[`descending()`](/categories-query-builder/descending)|
|`postCount`|[`eq()`](/categories-query-builder/eq),[`ne()`](/categories-query-builder/ne),[`lt()`](/categories-query-builder/lt),[`le()`](/categories-query-builder/le),[`gt()`](/categories-query-builder/gt),[`ge()`](/categories-query-builder/ge),[`in()`](/categories-query-builder/in),[`ascending()`](/categories-query-builder/ascending),[`descending()`](/categories-query-builder/descending)|
|`title`|[`eq()`](/categories-query-builder/eq),[`ne()`](/categories-query-builder/ne),[`startsWith()`](/categories-query-builder/starts-with),[`exists()`](/categories-query-builder/exists),[`in()`](/categories-query-builder/in),[`ascending()`](/categories-query-builder/ascending),[`descending()`](/categories-query-builder/descending)|
|`displayPosition`|[`eq()`](/categories-query-builder/eq),[`ne()`](/categories-query-builder/ne),[`lt()`](/categories-query-builder/lt),[`le()`](/categories-query-builder/le),[`gt()`](/categories-query-builder/gt),[`ge()`](/categories-query-builder/ge),[`in()`](/categories-query-builder/in),[`ascending()`](/categories-query-builder/ascending),[`descending()`](/categories-query-builder/descending)|
|`translationId`|[`eq()`](/categories-query-builder/eq),[`ne()`](/categories-query-builder/ne),[`exists()`](/categories-query-builder/exists),[`in()`](/categories-query-builder/in)|
|`language`|[`eq()`](/categories-query-builder/eq),[`ne()`](/categories-query-builder/ne),[`exists()`](/categories-query-builder/exists),[`in()`](/categories-query-builder/in),[`ascending()`](/categories-query-builder/ascending),[`descending()`](/categories-query-builder/descending)|
|`slug`|[`eq()`](/categories-query-builder/eq),[`ne()`](/categories-query-builder/ne),[`exists()`](/categories-query-builder/exists),[`in()`](/categories-query-builder/in),[`ascending()`](/categories-query-builder/ascending),[`descending()`](/categories-query-builder/descending)|



# Method Code Examples:

*** Note: do not assume any prop names or enum values other than the ones in the example.

## Retrieve a list of all categories

```javascript
import { categories } from 'wix-blog-backend';

export async function queryCategoriesFunction() {
  try {
    const results = await categories.queryCategories().find();
    const items = results.items;
    const firstItem = items[0];
    const pageSize = results.pageSize;
    const hasNext = results.hasNext();
    const hasPrev = results.hasPrev();
    const length = results.length;
    const query = results.query;
    return items;
  } catch (error) {
    console.error(error);
  }
}

/* Returns:
 * [
 *   {
 *     "_id": "f489bf39-3297-4854-8429-e19dbefdca0e",
 *     "coverImage": "wix:image://v1/162e66_f6bffd1cd6144ddf87325b82fe8f42ed~mv2.jpg#originWidth=385&originHeight=245",
 *     "description": "my category description",
 *     "displayPosition": 0,
 *     "label": "My Category",
 *     "language": "en",
 *     "postCount": 1,
 *     "slug": "my-category",
 *     "title": "My Category",
 *     "translationId": "dfc5b1a7-df04-4596-b311-9724f0477c3e"
 *   },
 *   {
 *     "_id": "686d5dd8-317a-4e3a-96b5-fe25f107aafd",
 *     "coverImage": "wix:image://v1/162e66_f6bffd1cd6144ddf87325b82fe8f42ed~mv2.jpg#originWidth=385&originHeight=245",
 *     "description": "my category description",
 *     "displayPosition": 1,
 *     "label": "My Category 2",
 *     "language": "lt",
 *     "postCount": 0,
 *     "slug": "my-category-2",
 *     "title": "My Category 2",
 *     "translationId": "dfc5b1a7-df04-4596-b311-9724f0477c3e"
 *   },
 *   {
 *     "_id": "1ea22fce-bc3c-4b78-9422-f0f367f8628e",
 *     "coverImage": "wix:image://v1/162e66_f6bffd1cd6144ddf87325b82fe8f42ed~mv2.jpg#originWidth=385&originHeight=245",
 *     "description": "Posts about my summer",
 *     "displayPosition": 2,
 *     "label": "Summer",
 *     "language": "en",
 *     "postCount": 6,
 *     "slug": "summer-slug",
 *     "title": "Summer",
 *     "translationId": "973369ad-0d4b-41f5-a820-1eed7986e0de"
 *   },
 *   {
 *     "_id": "8bb208d0-bc3d-4caa-bbbf-775e52851d8f",
 *     "coverImage": "wix:image://v1/162e66_f6bffd1cd6144ddf87325b82fe8f42ed~mv2.jpg#originWidth=385&originHeight=245",
 *     "description": "Posts about my holidays",
 *     "displayPosition": 3,
 *     "label": "holidays",
 *     "language": "en",
 *     "postCount": 0,
 *     "slug": "holidays",
 *     "title": "Holidays",
 *     "translationId": ""
 *   }
 * ]
 */

```

## Retrieve a list of all categories (export from backend code)

```javascript
import { Permissions, webMethod } from 'wix-web-module';
import { categories } from 'wix-blog-backend';

export const queryCategoriesFunction = webMethod(Permissions.Anyone, async () => {
  try {
    const results = await categories.queryCategories().find();
    const items = results.items;
    const firstItem = items[0];
    const pageSize = results.pageSize;
    const hasNext = results.hasNext();
    const hasPrev = results.hasPrev();
    const length = results.length;
    const query = results.query;
    return items;
  } catch (error) {
    console.error(error);
  }
});

/* Returns:
 * [
 *   {
 *     "_id": "f489bf39-3297-4854-8429-e19dbefdca0e",
 *     "coverImage": "wix:image://v1/162e66_f6bffd1cd6144ddf87325b82fe8f42ed~mv2.jpg#originWidth=385&originHeight=245",
 *     "description": "my category description",
 *     "displayPosition": 0,
 *     "label": "My Category",
 *     "language": "en",
 *     "postCount": 1,
 *     "slug": "my-category",
 *     "title": "My Category",
 *     "translationId": "dfc5b1a7-df04-4596-b311-9724f0477c3e"
 *   },
 *   {
 *     "_id": "686d5dd8-317a-4e3a-96b5-fe25f107aafd",
 *     "coverImage": "wix:image://v1/162e66_f6bffd1cd6144ddf87325b82fe8f42ed~mv2.jpg#originWidth=385&originHeight=245",
 *     "description": "my category description",
 *     "displayPosition": 1,
 *     "label": "My Category 2",
 *     "language": "lt",
 *     "postCount": 0,
 *     "slug": "my-category-2",
 *     "title": "My Category 2",
 *     "translationId": "dfc5b1a7-df04-4596-b311-9724f0477c3e"
 *   },
 *   {
 *     "_id": "1ea22fce-bc3c-4b78-9422-f0f367f8628e",
 *     "coverImage": "wix:image://v1/162e66_f6bffd1cd6144ddf87325b82fe8f42ed~mv2.jpg#originWidth=385&originHeight=245",
 *     "description": "Posts about my summer",
 *     "displayPosition": 2,
 *     "label": "Summer",
 *     "language": "en",
 *     "postCount": 6,
 *     "slug": "summer-slug",
 *     "title": "Summer",
 *     "translationId": "973369ad-0d4b-41f5-a820-1eed7986e0de"
 *   },
 *   {
 *     "_id": "8bb208d0-bc3d-4caa-bbbf-775e52851d8f",
 *     "coverImage": "wix:image://v1/162e66_f6bffd1cd6144ddf87325b82fe8f42ed~mv2.jpg#originWidth=385&originHeight=245",
 *     "description": "Posts about my holidays",
 *     "displayPosition": 3,
 *     "label": "holidays",
 *     "language": "en",
 *     "postCount": 0,
 *     "slug": "holidays",
 *     "title": "Holidays",
 *     "translationId": ""
 *   }
 * ]
 */
```

## Query for a category with filters 

```javascript
import { Permissions, webMethod } from 'wix-web-module';
import { categories } from 'wix-blog-backend';

/* Sample options values:
 * {
 *   fieldsets: [
 *     'URL'
 *   ]
 * }
 */

export const queryCategoriesFunction = webMethod(Permissions.Anyone, async () => {
  try {
    const result = await categories.queryCategories({fieldsets: ['URL']})
      .descending('label')
      .lt('displayPosition', 3)
      .find();
    console.log('Retrieved result:', result.items);
    return result.items;
  } catch (error) {
    console.log(error);
  }
});

/* Returns:
 * [
 *   {
 *     "_id": "1ea22fce-bc3c-4b78-9422-f0f367f8628e",
 *     "coverImage": "wix:image://v1/162e66_f6bffd1cd6144ddf87325b82fe8f42ed~mv2.jpg#originWidth=385&originHeight=245",
 *     "description": "Posts about my summer",
 *     "displayPosition": 2,
 *     "label": "Summer",
 *     "language": "en",
 *     "postCount": 6,
 *     "slug": "summer-slug"
 *     "title": "Summer",
 *     "translationId": "973369ad-0d4b-41f5-a820-1eed7986e0de",
 *     "url": "http://https://tadasz7.wixsite.com/blog-velo-events/my-blog/categories/summer-slug"
 *   },
 *   {
 *     "_id": "f489bf39-3297-4854-8429-e19dbefdca0e",
 *     "coverImage": "wix:image://v1/162e66_f6bffd1cd6144ddf87325b82fe8f42ed~mv2.jpg#originWidth=385&originHeight=245"
 *     "description": "my category description",
 *     "displayPosition": 0,
 *     "label": "My Category",
 *     "language": "en",
 *     "postCount": 1,
 *     "slug": "my-category",
 *     "title": "My Category",
 *     "translationId": "dfc5b1a7-df04-4596-b311-9724f0477c3e",
 *     "url": "http://https://tadasz7.wixsite.com/blog-velo-events/my-blog/categories/my-category"
 *   },
 *   {
 *     "_id": "686d5dd8-317a-4e3a-96b5-fe25f107aafd",
 *     "coverImage": "wix:image://v1/162e66_f6bffd1cd6144ddf87325b82fe8f42ed~mv2.jpg#originWidth=385&originHeight=245"
 *     "description": "my category description",
 *     "displayPosition": 1,
 *     "label": "My Category 2",
 *     "language": "lt",
 *     "postCount": 0,
 *     "slug": "my-category-2",
 *     "title": "My Category 2",
 *     "translationId": "dfc5b1a7-df04-4596-b311-9724f0477c3e",
 *     "url": "http://https://tadasz7.wixsite.com/blog-velo-events/my-blog/categories/my-category-2"
 *   }
 * ]
 */

```

---