Search.../

getTagByLabel( )

Gets a tag by the specified label.

Description

The getTagByLabel() function returns a Promise that resolves to a tag whose label matches the specified label.

Syntax

function getTagByLabel(label: string, options: GetTagByLabelOptions): Promise<GetTagByLabelResponse>

getTagByLabel Parameters

NAME
TYPE
DESCRIPTION
label
string

Tag label.

options
Optional
GetTagByLabelOptions

Options specifying which additional fields to return.

Returns

Return Type:

Promise<
GetTagByLabelResponse
>
NAME
TYPE
DESCRIPTION
tag
Tag

Tag info.

Was this helpful?

Get a tag by its label

Copy Code
1import { tags } from 'wix-blog-backend';
2
3/* Sample label value:
4 * 'my tag'
5 */
6
7export async function getTagByLabelFunction(tagId) {
8 try {
9 const result = await tags.getTagByLabel(tagId);
10 const label = result.tag.label;
11 const postCount = result.tag.postCount;
12 console.log('Retrieved result:', result);
13 return result;
14 } catch (error) {
15 console.error(error);
16 };
17}
18
19
20/* Promise resolves to:
21 * {
22 * "tag": {
23 * "_createdDate": "2022-07-19T10:30:03.607Z",
24 * "_id": "32970480-e53b-46e7-b52f-fba810a0b45d",
25 * "_updatedDate": "2022-07-19T10:30:03.607Z",
26 * "label": "my tag",
27 * "language": "en",
28 * "postCount": 1,
29 * "publishedPostCount": 1,
30 * "slug": "my-tag",
31 * "translationId": ""
32 * }
33 * }
34 */
Get a tag by its label with additional fields

Copy Code
1import { tags } from 'wix-blog-backend';
2
3/* Sample label value:
4 * 'my tag'
5 * Sample options value:
6 * {
7 * fieldsets:
8 * [
9 * 'URL'
10 * ]
11 * }
12 */
13
14export async function getTagByLabelFunction(tagId, options) {
15 try {
16 const result = await tags.getTagByLabel(tagId, options);
17 const label = result.tag.label;
18 const postCount = result.tag.postCount;
19 const url = result.tag.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 * "tag": {
30 * "_createdDate": "2022-07-19T10:30:03.607Z",
31 * "_id": "32970480-e53b-46e7-b52f-fba810a0b45d",
32 * "label": "my tag",
33 * "slug": "my-tag",
34 * "_updatedDate": "2022-07-19T10:30:03.607Z",
35 * "postCount": 1,
36 * "publishedPostCount": 1,
37 * "language": "en",
38 * "translationId": "",
39 * "url": "http://https://tadasz7.wixsite.com/blog-velo-events/my-blog/tags/my-tag"
40 * }
41 * }
42 */
43