Search.../

getTag( )

Gets a tag by the specified ID.

Description

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

Syntax

function getTag(tagId: string, options: GetTagOptions): Promise<Tag>

getTag Parameters

NAME
TYPE
DESCRIPTION
tagId
string

Tag ID.

options
Optional
GetTagOptions

Options specifying which additional fields to return.

Returns

Tag info.

Return Type:

Promise<
Tag
>
NAME
TYPE
DESCRIPTION
_createdDate
Date

Date the tag was created.

_id
string

Tag ID.

_updatedDate
Date

Date the tag was last updated.

label
string

Tag label.

A blog can't have two tags with the same label.

language
string

Tag language.

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

postCount
number

Number of posts with this tag, including unpublished draft posts.

publicationCount
number

Reserved for internal use.

publishedPostCount
number

Number of published posts with this tag.

slug
string

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

For example, 'https:/example.com/tags/{my-tag-slug}'.

translationId
string

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

url
string

Tag URL.

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

Was this helpful?

Get a tag by ID

Copy Code
1import { tags } from 'wix-blog-backend';
2
3/* Sample tagId value:
4 * '32970480-e53b-46e7-b52f-fba810a0b45d'
5 */
6
7export async function getTagFunction(tagId) {
8 try {
9 const result = await tags.getTag(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 ID with additional fields

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