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 with additional fields and paging options

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

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