Search.../

getCategory( )

Gets a category by the specified ID.

Description

The getCategory() function returns a Promise that resolves to a category whose ID matches the specified ID.

Syntax

function getCategory(categoryId: string, options: GetCategoryOptions): Promise<Category>

getCategory Parameters

NAME
TYPE
DESCRIPTION
categoryId
string

Category ID.

options
Optional
GetCategoryOptions

Options specifying which fields to return.

Returns

Category info.

Return Type:

Promise<
Category
>
NAME
TYPE
DESCRIPTION
_id
string

Category ID.

coverImage
string

Category cover image.

coverMedia
CoverMedia

Reserved for internal use.

description
string

Category description.

displayPosition
number

Position of the category in the Category Menu. Categories with lower display position are displayed first.

internalId
string

Reserved for internal use.

label
string

Category label. Displayed in the Category Menu.

language
string

Category Language.

2-letter language code in ISO 639-1 format.

oldRank
number

Reserved for internal use.

postCount
number

Number of posts in the category.

rank
number

Reserved for internal use.

seoData
SeoSchema

SEO data.

slug
string

Part of a category's URL that refers to a specific category.

For example, 'https:/example.com/blog/category/{my-category-slug}'.

title
string

Category title.

translationId
string

ID of the category's translations when Wix Multilingual is installed on a site. All translations of a single category will share the same translationId.

url
string

Category URL.

The url directs you to a page that lists every post with the specified category.

Was this helpful?

Get a category by ID

Copy Code
1import { categories } from 'wix-blog-backend';
2
3/* Sample categoryId value:
4 * 'f489bf39-3297-4854-8429-e19dbefdca0e'
5 */
6
7export async function getCategoryFunction(categoryId) {
8 try {
9 const result = await categories.getCategory(categoryId);
10 const label = result.category.label;
11 const slug = result.category.slug;
12 console.log('Retrieved Result:', result);
13 return result;
14 } catch (error) {
15 console.error(error);
16 }
17}
18
19/* Promise resolves to:
20 * {
21 * "category": {
22 * "_id": "f489bf39-3297-4854-8429-e19dbefdca0e",
23 * "coverImage": "wix:image://v1/162e66_f6bffd1cd6144ddf87325b82fe8f42ed~mv2.jpg#originWidth=385&originHeight=245",
24 * "description": "my category description",
25 * "displayPosition": 0,
26 * "label": "My Category",
27 * "language": "en",
28 * "postCount": 1,
29 * "slug": "my-category",
30 * "title": "My Category",
31 * "translationId": "dfc5b1a7-df04-4596-b311-9724f0477c3e"
32 * }
33 * }
34 */
35
Get a category by ID with additional fields

Copy Code
1import { categories } from 'wix-blog-backend';
2
3/* Sample categoryId value:
4 * 'f489bf39-3297-4854-8429-e19dbefdca0e'
5 *
6 * Sample options value:
7 * {
8 * fieldsets: [
9 * 'URL',
10 * 'SEO'
11 * ]
12 * }
13 */
14
15export async function getCategoryFunction(categoryId, options) {
16 try {
17 const result = await categories.getCategory(categoryId, options);
18 const label = result.category.label;
19 const url = result.category.url;
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 * "category": {
30 * "_id": "f489bf39-3297-4854-8429-e19dbefdca0e",
31 * "coverImage": "wix:image://v1/162e66_f6bffd1cd6144ddf87325b82fe8f42ed~mv2.jpg#originWidth=385&originHeight=245",
32 * "description": "my category description",
33 * "displayPosition": 0,
34 * "label": "My Category",
35 * "language": "en",
36 * "postCount": 1,
37 * "seoData": {
38 * "tags": [
39 * {
40 * "type": "meta",
41 * "props": {
42 * "name": "description",
43 * "content": "this is a category description"
44 * },
45 * "children": "",
46 * "custom": false,
47 * "disabled": false
48 * }
49 * ]
50 * },
51 * "slug": "my-category",
52 * "title": "My Category",
53 * "translationId": "dfc5b1a7-df04-4596-b311-9724f0477c3e",
54 * "url" : "http://https://tadasz7.wixsite.com/blog-velo-events/my-blog/categories/my-category"
55 * }
56 * }
57 */
58