Search.../

listCategories( )

Retrieves a list of categories.

Description

The listCategories() function returns a Promise that resolves to a list of up to 100 categories per language in order of their displayPosition starting with 0. The displayPosition is the position in which the categories are displayed in the Category Menu page. By default, categories get added to the bottom of the Category Menu with a displayPosition of -1.

Syntax

function listCategories(options: ListCategoriesOptions): Promise<ListCategoriesResponse>

listCategories Parameters

NAME
TYPE
DESCRIPTION
options
Optional
ListCategoriesOptions

Filter and paging options.

Returns

Return Type:

Promise<
ListCategoriesResponse
>
NAME
TYPE
DESCRIPTION
categories
Array<
Category
>

List of categories.

metaData
MetaData

Details on the paged set of results returned.

Was this helpful?

List blog categories

Copy Code
1import { categories } from 'wix-blog-backend';
2
3export async function listCategoriesFunction() {
4 try {
5 const result = await categories.listCategories();
6 const firstCategoryLabel = result.categories[0].label;
7 const firstCategoryId = result.categories[0]._id;
8 console.log('Retrieved Result:', result);
9 return result;
10 } catch (error) {
11 console.error(error);
12 }
13}
14
15/* Promise resolves to:
16 * {
17 * "categories": [
18 * {
19 * "_id": "f489bf39-3297-4854-8429-e19dbefdca0e",
20 * "coverImage": "wix:image://v1/162e66_f6bffd1cd6144ddf87325b82fe8f42ed~mv2.jpg#originWidth=385&originHeight=245",
21 * "description": "my category description",
22 * "displayPosition": 0,
23 * "label": "My Category",
24 * "language": "en",
25 * "postCount": 1,
26 * "slug": "my-category",
27 * "title": "My Category",
28 * "translationId": "dfc5b1a7-df04-4596-b311-9724f0477c3e"
29 * },
30 * {
31 * "_id": "1ea22fce-bc3c-4b78-9422-f0f367f8628e",
32 * "description": "Posts about my summer",
33 * "displayPosition": 1,
34 * "label": "Summer",
35 * "language": "en",
36 * "postCount": 6,
37 * "slug": "summer-slug"
38 * "title": "My Category",
39 * "translationId": "973369ad-0d4b-41f5-a820-1eed7986e0de"
40 * },
41 * ],
42 * "metaData": {
43 * "count": 2,
44 * "offset": 0,
45 * "total": 2
46 * }
47 * }
48 */
49
List blog categories (export from backend code)

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { categories } from 'wix-blog-backend';
3
4export const listCategoriesFunction = webMethod(Permissions.Anyone, async () => {
5 try {
6 const result = await categories.listCategories();
7 const firstCategoryLabel = result.categories[0].label;
8 const firstCategoryId = result.categories[0]._id;
9 console.log('Retrieved Result:', result);
10 return result;
11 } catch (error) {
12 console.error(error);
13 }
14});
15
16/* Promise resolves to:
17 * {
18 * "categories": [
19 * {
20 * "_id": "f489bf39-3297-4854-8429-e19dbefdca0e",
21 * "coverImage": "wix:image://v1/162e66_f6bffd1cd6144ddf87325b82fe8f42ed~mv2.jpg#originWidth=385&originHeight=245",
22 * "description": "my category description",
23 * "displayPosition": 0,
24 * "label": "My Category",
25 * "language": "en",
26 * "postCount": 1,
27 * "slug": "my-category",
28 * "title": "My Category",
29 * "translationId": "dfc5b1a7-df04-4596-b311-9724f0477c3e"
30 * },
31 * {
32 * "_id": "1ea22fce-bc3c-4b78-9422-f0f367f8628e",
33 * "description": "Posts about my summer",
34 * "displayPosition": 1,
35 * "label": "Summer",
36 * "language": "en",
37 * "postCount": 6,
38 * "slug": "summer-slug"
39 * "title": "My Category",
40 * "translationId": "973369ad-0d4b-41f5-a820-1eed7986e0de"
41 * },
42 * ],
43 * "metaData": {
44 * "count": 2,
45 * "offset": 0,
46 * "total": 2
47 * }
48 * }
49 */
50
List blog categories with additional fields and paging options

This example uses the options parameter to add additional fields and page the blog categories.

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { categories } from 'wix-blog-backend';
3
4/* Sample options values:
5 * {
6 * fieldsets: [
7 * 'URL',
8 * 'SEO',
9 * ],
10 * paging: {
11 * limit: 2
12 * }
13 * }
14 */
15
16export const listCategoriesFunction = webMethod(Permissions.Anyone, async (options) => {
17 try {
18 const result = await categories.listCategories(options);
19 const firstCategoryLabel = result.categories[0].label;
20 const firstCategoryId = result.categories[0]._id;
21 console.log('Retrieved Result:', result);
22 return result;
23 } catch (error) {
24 console.error(error);
25 }
26});
27
28/* Promise resolves to:
29 * {
30 * "categories": [
31 * {
32 * "_id": "f489bf39-3297-4854-8429-e19dbefdca0e",
33 * "coverImage": "wix:image://v1/162e66_f6bffd1cd6144ddf87325b82fe8f42ed~mv2.jpg#originWidth=385&originHeight=245",
34 * "description": "my category description",
35 * "displayPosition": 0,
36 * "label": "My Category",
37 * "language": "en",
38 * "postCount": 1,
39 * "seoData": {
40 * "tags": [
41 * {
42 * "type": "meta",
43 * "props": {
44 * "name": "description",
45 * "content": "this is a category description"
46 * },
47 * "children": "",
48 * "custom": false,
49 * "disabled": false
50 * }
51 * ]
52 * },
53 * "slug": "my-category",
54 * "title": "My Category",
55 * "translationId": "dfc5b1a7-df04-4596-b311-9724f0477c3e",
56 * "url": "http://https://tadasz7.wixsite.com/blog-velo-events/my-blog/categories/my-category"
57 * },
58 * {
59 * "_id": "1ea22fce-bc3c-4b78-9422-f0f367f8628e",
60 * "description": "Posts about my summer",
61 * "displayPosition": 1,
62 * "label": "Summer",
63 * "language": "en",
64 * "postCount": 6,
65 * "seoData": {
66 * "tags": [
67 * {
68 * "type": "meta",
69 * "props": {
70 * "name": "description",
71 * "content": "Summer is the BEST season"
72 * },
73 * "children": "",
74 * "custom": false,
75 * "disabled": false
76 * }
77 * ]
78 * },
79 * "slug": "summer-slug"
80 * "title": "Summer",
81 * "translationId": "973369ad-0d4b-41f5-a820-1eed7986e0de",
82 * "url": "http://https://tadasz7.wixsite.com/blog-velo-events/my-blog/categories/summer-slug"
83 * },
84 * ],
85 * "metaData": {
86 * "count": 2,
87 * "offset": 0,
88 * "total": 6,
89 * "cursor": "eyJmaWx0ZXIiOnt9LCJ2YWx1ZSI6eyJyYW5rIjowfSwib3JkZXIiOnsicmFuayI6MSwiX2lkIjoxfX0="
90 * }
91 * }
92 */